waveform80 / picamera

A pure Python interface to the Raspberry Pi camera module
https://picamera.readthedocs.io/
BSD 3-Clause "New" or "Revised" License
1.57k stars 357 forks source link

PiCamera - variation between preview and capture #254

Open kkjkearney opened 8 years ago

kkjkearney commented 8 years ago

I've created a microscope application using a Raspberry Pi 2 and a Raspberry Pi camera board. I'm programming in Python using PyGame, cv2 and picamera 1.10. Works great, with one exception. Previewing to the screen looks great, with a very responsive image, good colors and excellent reaction to changing light conditions. However when I capture, the image takes on strange hues and the white balance appears to be performing poorly. Capture seems unable to adjust to various lighting conditions, at least compared to preview. If I could, I'd capture exactly what I'm seeing in preview mode and manipulate that image in pygame. I've tried querying all preview settings such as awb_gains and forcing that upon the capture, but the results look worse. I've queried and observed that the digital_gain is different when previewing and capturing, but I have no control over that. I've tried capturing from the video port, but similar results.
Any suggestions?

waveform80 commented 7 years ago

Sorry, looks like this is another ticket that slipped through the cracks. In case you're still interested:

When the camera's asked to produce a still capture (where use_video_port is False) a lot of work goes on under the covers including changing the sensor's mode a couple of times and using some strong denoise algorithms. The white balance shouldn't change significantly from the preview, but I've sometimes observed some differences, particularly when the sensor mode goes from a binned mode (in preview) to a non-binned one (when capturing).

Using video port captures (use_video_port=True) is rather different and tends to produce almost exactly the same output as the preview (as no mode switch is involved and weaker denoise algorithms are applied). I've never seen significant white balance variations in this case (I'd be interested to see them though!).

You could try capturing a still and video port image almost simultaneously for comparison. Alternatively, you can capture directly from the preview port - not using picamera's high level API but the lower level mmalobj layer (introduced in 1.11) permits such things. Check out the MMAL tour in the docs for more information on this.