Page 1 of 1

Over exposed stills from PiCamera (via Node-RED)

Posted: Sat Aug 19, 2017 1:36 pm
by Lomax
I'm pretty excited to have Node-RED email me still images from a CSI attached camera when certain events occur, courtesy of the CameraPi Node-RED node. The more I'm using it, the more impressed I am by Node-RED. But there's a problem: the captured images tend to be severely over exposed, to the point of being almost completely washed out (when the sun is shining at least) - it seems no auto exposure adjustment is being made, but who is to blame for this; the CameraPi code, the PiCamera Python library it uses, or some lower level configuration on my Pi? Frankly, I'm a little lost and would appreciate any pointers!

Re: Over exposed stills from PiCamera (via Node-RED)

Posted: Sat Aug 19, 2017 3:32 pm
by 6by9
Looks to be the CameraPi code not following best (required) practice

https://github.com/O-Hahn/node-red-cont ... oto.py#L49
creates the camera and almost immediately calls capture(). That gives no time for AE, AGC, or AWB to adapt to the scene. All the examples in the PiCamera documentation include a "time.sleep(2)" between creating the camera and calling capture for exactly this reason. You need at least 300ms, and generally more like 800ms, depending on the frame rate, exposure mode, and some other capture options that are used.

Re: Over exposed stills from PiCamera (via Node-RED)

Posted: Sat Aug 19, 2017 3:50 pm
by Lomax
That's fabulous, thank you very much! I have seen some mentions of having to wait a moment before capturing, to allow the camera to adjust exposure, but my application is heavily asynchronous so I would never have noticed any ~1s delay - your reply makes the situation perfectly clear. Should be dead easy to add a setTimeout wrapping to the CameraPi JS - looking at it now.

Re: Over exposed stills from PiCamera (via Node-RED)

Posted: Sat Aug 19, 2017 7:06 pm
by Lomax
My bad, CameraPi instantiates the camera in Python, so the modification had to go in /home/nodered/.node-red/node_modules/node-red-contrib-camerapi/lib/python/get_photo.py. I added a simple time.sleep(1) in the camera initialisation code:

Code: Select all

        camera.image_effect = imageeffect
        time.sleep(1)
        camera.capture(picfile, i_format)

Now checking what effect it had, if any, on exposure / AGC.

Re: Over exposed stills from PiCamera (via Node-RED)

Posted: Sat Aug 19, 2017 7:11 pm
by Lomax
Yep, early indications are this has done the trick, though the sun has now disappeared so will have to wait until tomorrow for final proof.

Edit: Another bright and sunny day here, and my still images are no longer washed out. Thanks @6by9!