I use openHAB and want to use an old mobile phone as an day/night indicator. I have installed a webcam app and it is filming the sky. I can get the latest shot via .
Can I get a "brightness value" like this: curl | some-command --get-brightness?
2 Answers
Question is answered here on Software Recommendations Stack Exchange by Steve Barnes.
Two possibilities:
Use imagemagick to check the brightness of the image will work as long as the phone camera does not have auto-exposure or it is turned off, otherwise it will only work for extreme values, (dark/light), e.g.
convert <image> -colorspace Gray -format "%[fx:quantumrange*image.mean]" info:exiftool can parse the EXIF information from the file and extract the "Light Value" which should give you a reasonably consistent reading, (assuming that the camera on your specific phone includes this tag).
Both tools are free, gratis & open source and available for most platforms.
Alternatively to exiftool, you can use exiv2, which I found to be much faster than exiftool and imagemagick.
Comparison (on Raspberry Pi Zero)
Tested with always the same 4056 x 3040 image
Imagemagick convert
pi@rpicamhq:/mnt/ramdisk $ time convert image.jpg -colorspace Gray -format "%[fx:quantumrange*image.mean]" info:
1039.34
real 0m1,989s
user 0m1,753s
sys 0m0,193sImagemagick identify format
pi@rpicamhq:/mnt/ramdisk $ time identify -format "%[mean]\n" image.jpg
1128.99
real 0m3,357s
user 0m3,133s
sys 0m0,199s
pi@rpicamhq:/mnt/ramdisk $ time identify -format "%[fx:mean]\n" image.jpg
0.0172272
real 0m3,435s
user 0m3,274s
sys 0m0,130s
pi@rpicamhq:/mnt/ramdisk $ time identify -format "%[fx:quantumrange*mean]\n" image.jpg
1128.99
real 0m3,387s
user 0m3,218s
sys 0m0,139sImagemagick identify exif
pi@rpicamhq:/mnt/ramdisk $ time identify -format '%[EXIF:BrightnessValue]'
real 0m0,275s
user 0m0,071s
sys 0m0,040sexiftool
pi@rpicamhq:/mnt/ramdisk $ time exiftool -a -u -g1 image.jpg | grep 'Brightness'
Brightness Value : 0.01
real 0m2,647s
user 0m2,429s
sys 0m0,191sexiv2
pi@rpicamhq:/mnt/ramdisk $ time exiv2 -PElt image.jpg | grep 'Brightness'
Brightness 0.01
real 0m0,097s
user 0m0,042s
sys 0m0,050sexiv2, w/o grep
pi@rpicamhq:/mnt/ramdisk $ time exiv2 -PElt -g Brightness image.jpg
Brightness 0.01
real 0m0,070s
user 0m0,024s
sys 0m0,039s 0