I have posed this question on the Picamera Github issues forum but it has not been answered in nearly a month. Hoping for better luck here.
I am running a Pi Camera v2.1 in an industrial measurement environment and control over exposure speed is critical. Pi 2 B is running Raspbian stretch and using Python 3.5.3 with the picamera 1.13 package.
The problem is that after setting camera.shutter_speed
to a specific exposure time value (in us), each image retrieved from the camera is darker and darker, and camera.exposure_speed
drops by about 75-76 us each frame, until the minimum exposure speed of 9 us is reached. If camera.shutter_speed
is written before every frame is retrieved, then camera.exposure_speed
drops only once, by 76 us. See comments in code below.
Setting breakpoints in the Picamera module code shows that the exposure_speed
value read from its MMAL structure is in fact changing.
I am using the following code to allocate the camera and lock its exposure system.
from picamera.array import PiArrayOutput
from picamera import PiCamera
from time import sleep
camera = PiCamera(sensor_mode=2)
camera.resolution = camera.MAX_RESOLUTION
camera.framerate = 5
camera.awb_mode = 'off'
camera.iso = 60 # Set ISO to force unity gains, then lock...
camera.exposure_mode = 'off' # ... locks gains
camera.shutter_speed = 1000
sleep(2) # Ensure gains are locked and report correctly
and this code to retrieve images (using the full Bayer array data).
bayer_capture = PiArrayOutput(camera, (2480, 4128))
stream = camera.capture_continuous(bayer_capture, format='jpeg', bayer=True, quality=1, thumbnail=None)
for f in stream:
# If shutter speed is forced after every image, the exposure_speed drop
# occurs only for the first frame
#camera.shutter_speed = 1000
print("exp: {}".format(camera.exposure_speed))
The output of this simple program is as follows.
exp: 936
exp: 860
exp: 784
exp: 709
exp: 633
exp: 558
exp: 482
exp: 406
exp: 331
exp: 255
exp: 180
exp: 104
exp: 28
exp: 9
exp: 9
Note that the camera.exposure_speed
is reducing by 75 - 76 us for each image.
Other background:
With a Pi Camera v1.3 this code works fine: the image does not dim, camera.exposure_speed
holds constant and equals camera.shutter_speed
. With Pi Camera v2.1 before about February 2018, it also worked fine. Around early Feb 2018 I did a Raspbian update, but looking through changelogs neither picamera
nor raspberrypi-firmware
was updated around then. I do not use rpi-update
.
Is there something obvious I am missing? Is anyone else having this problem?
UPDATE 4/12/18:
Substantially simpler code example that exhibits the same problem is below. The problem seems to be triggered by a write to either camera.shutter_speed
or camera.exposure_mode
. When both of those assignments are commented out in the code below, the camera maintains a controlled exposure time as long as the light entering the sensor is held constant (since the camera is not in locked exposure mode). When either or both assignments are uncommented, camera.exposure_speed
drops on each frame.
from picamera import PiCamera
from time import sleep
import io
with PiCamera(sensor_mode=2) as camera:
camera.exposure_mode = 'off' # Lock gains and disable auto exposure
camera.shutter_speed = 1000
sleep(1) # Let shutter speed take effect
stream = camera.capture_continuous(io.BytesIO(), format='jpeg')
for f in stream:
print("exp: {}".format(camera.exposure_speed))