Webcam image, how to check if it's getting dark?

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
rudy
Posts: 2
Joined: 2012-06-21T04:45:45-07:00
Authentication code: 13

Webcam image, how to check if it's getting dark?

Post by rudy »

I want to use my webcam to switch on some lights.
The webcam switches to gray colorspace at some time (that's a easy to check with imagemagick), but I wan't to switch it on before it's getting really dark.

I looked and tried at a lot of examples for measuring darkness, but didn't find a proper solution.
I tried colorspace, standard_deviation, some things with histogram, but it's a little complex for me.
Could somebody give me some tips?
tsftd
Posts: 28
Joined: 2012-01-14T11:46:55-07:00
Authentication code: 8675308

Re: Webcam image, how to check if it's getting dark?

Post by tsftd »

a bit late, but you could just grab a certain number of individual pixel values (say, every 10th pixel), add the brightness together, store it, and check it against previous stored data. when the comparison shows enough "darkening" -- ie, average brightness decrease, it's getting dark. though i doubt you could realistically do that with anything but an API and actual code. it'd be fairly trivial to do it with magick++.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Webcam image, how to check if it's getting dark?

Post by fmw42 »

The string format "%[mean] or %[fx:mean] tells you the average graylevel of the image.

convert image -format "%[fx:mean]" info:

will tell you a value between 0 and 1. So you can scale to percent by

convert image -format "%[fx:100*mean]%%" info:

or

identify -format "%[fx:100*mean]%%" image


The %[mean] gives you the mean in absolute graylevel but that will depend upon your IM compile Q8 or Q16.
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: Webcam image, how to check if it's getting dark?

Post by Bonzo »

The webcam switches to gray colorspace at some time
I assume the webcam is colour when its light and it converts to grayscale at a certain light level and it is to late at that point?
rudy
Posts: 2
Joined: 2012-06-21T04:45:45-07:00
Authentication code: 13

Re: Webcam image, how to check if it's getting dark?

Post by rudy »

Bonzo wrote:
The webcam switches to gray colorspace at some time
I assume the webcam is colour when its light and it converts to grayscale at a certain light level and it is to late at that point?
Yes, I want to switch the light on some time before that ( it's for my garden... so some nice light before it's getting to dark ).
It's also not on a regular interval, somedays you've got very dark days, so it should switch on earlier.

I'll will try the replies above (thanks) and keep you posted.
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Webcam image, how to check if it's getting dark?

Post by anthony »

You may need to specifically select 'distant' or 'sky' pixels in the image for your test, otherwise the web came may turn on the light, but then turn it off again when the light goes on.

Perhaps a 'sky' mask for the scene the camera looks at.

Also watch your threshold levels. It may be dark because of light rain, or even very dark storms.
Or you could have low cloud light, lit up by a city building, make the camera think it is day!

Most automatic lights have a general sensor, pointing up, above the light itself, so the light source does not interfere with the sensor.
Same does for solar lights, with uses the charging solar panel as the sensor.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Post Reply