Lomax
Posts: 188
Joined: Wed May 20, 2015 9:43 pm

Over exposed stills from PiCamera (via Node-RED)

Sat Aug 19, 2017 1:36 pm

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!

6by9
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 7132
Joined: Wed Dec 04, 2013 11:27 am
Location: ZZ9 Plural Z Alpha, aka just outside Cambridge.

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

Sat Aug 19, 2017 3:32 pm

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.
Software Engineer at Raspberry Pi Trading. Views expressed are still personal views.
I'm not interested in doing contracts for bespoke functionality - please don't ask.

Lomax
Posts: 188
Joined: Wed May 20, 2015 9:43 pm

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

Sat Aug 19, 2017 3:50 pm

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.

Lomax
Posts: 188
Joined: Wed May 20, 2015 9:43 pm

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

Sat Aug 19, 2017 7:06 pm

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.

Lomax
Posts: 188
Joined: Wed May 20, 2015 9:43 pm

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

Sat Aug 19, 2017 7:11 pm

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!

Return to “Camera board”