Getting consistent images (exposure-wise)
Posted: Mon Jul 06, 2015 7:46 am
Hello,
I am trying to get -very- consistent captures using Raspberry camera. Consistent in exposure/lightning.
I wrote a test script to observe the consistency of consecutive captures. This script:
1) Opens the camera
2) Fixes the framerate, resolution, shutter_speed, iso and awb_gains.
3) Captures a frame
4) Closes the camera
5) Goes to step 1 again.
Source code:
And when I look at the results. Although they are pretty consistent there are still subtle exposure differences between them.
But I wrote a second script which only opens the camera "once", fixes the same parameters and then captures all the frames before closing the camera. And then I get very consistent images.
Source code:
My questions are:
1) I guess the difference of these scripts is the digital_gain and analog_gain parameters which are reset between the captures on script 1. Whereas analog_gain and digital_gain parameters do not change on script 2 between captures. Is this true?
2) We observed that there is a position change due to camera overheat if I leave the camera open for a long time. That is why I need to close the camera and open it again between captures. Is there a way to get the exact same analog and digital gain parameters on every capture using script 1?
I am trying to get -very- consistent captures using Raspberry camera. Consistent in exposure/lightning.
I wrote a test script to observe the consistency of consecutive captures. This script:
1) Opens the camera
2) Fixes the framerate, resolution, shutter_speed, iso and awb_gains.
3) Captures a frame
4) Closes the camera
5) Goes to step 1 again.
Source code:
Code: Select all
import picamera
import time
use_video_port = True
white_balance_gains = None
i = 0
while True:
with picamera.PiCamera() as camera:
camera.framerate = 1
camera.resolution = (2592, 1944)
camera.shutter_speed = 8333 * 12
camera.iso = 100
if white_balance_gains is None:
time.sleep(3)
print("Fixing white balance gains.")
white_balance_gains = camera.awb_gains
camera.awb_mode = 'off'
camera.awb_gains = white_balance_gains
time.sleep(3)
camera.exposure_mode = 'off'
print("Capturing: " + str(i))
print("--------------")
print("White balance: " + str(camera.awb_gains))
print("White balance mode: " + str(camera.awb_mode))
print("ISO: " + str(camera.iso))
print("Shutter speed: " + str(camera.shutter_speed))
print("Brightness: " + str(camera.brightness))
print("Digital gain: " + str(camera.digital_gain))
print("Analog gain: " + str(camera.analog_gain))
print("Exposure compensation: " + str(camera.exposure_compensation))
print("\n")
#print(camera._get_camera_settings())
camera.capture("consistent_captures/" + str(i) + ".jpg", use_video_port=use_video_port)
i += 1
time.sleep(2)
But I wrote a second script which only opens the camera "once", fixes the same parameters and then captures all the frames before closing the camera. And then I get very consistent images.
Source code:
Code: Select all
import picamera
import time
use_video_port = True
white_balance_gains = None
with picamera.PiCamera() as camera:
camera.framerate = 1
camera.resolution = (2592, 1944)
camera.shutter_speed = 8333 * 12
camera.iso = 100
if white_balance_gains is None:
time.sleep(3)
print("Fixing white balance gains.")
white_balance_gains = camera.awb_gains
camera.awb_mode = 'off'
camera.awb_gains = white_balance_gains
time.sleep(3)
camera.exposure_mode = 'off'
i = 0
while True:
print("Capturing: " + str(i))
print("--------------")
print("White balance: " + str(camera.awb_gains))
print("White balance mode: " + str(camera.awb_mode))
print("ISO: " + str(camera.iso))
print("Shutter speed: " + str(camera.shutter_speed))
print("Brightness: " + str(camera.brightness))
print("Digital gain: " + str(camera.digital_gain))
print("Analog gain: " + str(camera.analog_gain))
print("Exposure compensation: " + str(camera.exposure_compensation))
print("\n")
#print(camera._get_camera_settings())
camera.capture("consistent_captures/" + str(i) + ".jpg", use_video_port=use_video_port)
i += 1
time.sleep(2)
1) I guess the difference of these scripts is the digital_gain and analog_gain parameters which are reset between the captures on script 1. Whereas analog_gain and digital_gain parameters do not change on script 2 between captures. Is this true?
2) We observed that there is a position change due to camera overheat if I leave the camera open for a long time. That is why I need to close the camera and open it again between captures. Is there a way to get the exact same analog and digital gain parameters on every capture using script 1?