Example: 01-Camera/07-Sensor-Control/sensor_save_and_restore_settings.py
import sensor
import time
target_pixformat = sensor.RGB565
target_framesize = sensor.QVGA
sensor.reset()
sensor.set_pixformat(target_pixformat)
sensor.set_framesize(target_framesize)
t = time.ticks_ms()
clock = time.clock()
fps = 0
while time.ticks_diff(time.ticks_ms(), t) < 3000:
clock.tick()
sensor.snapshot()
fps = clock.fps()
gain = sensor.get_gain_db()
exposure = sensor.get_exposure_us()
rgb_gain = sensor.get_rgb_gain_db()
print("Gain == %f db" % gain)
print("Exposure == %d us" % exposure)
print("RGB Gain == %f db, %f db, %f db" % (rgb_gain[0], rgb_gain[1], rgb_gain[2]))
print("Powering Off Sensor")
sensor.shutdown(True)
time.sleep(2)
sensor.disable_delays(True)
ts = time.ticks_ms()
print("Powering On Sensor")
sensor.shutdown(False)
sensor.reset()
sensor.set_pixformat(target_pixformat)
sensor.set_framesize(target_framesize)
sensor.set_auto_gain(False, gain_db=gain)
sensor.set_auto_exposure(False, exposure_us=exposure)
sensor.set_auto_whitebal(False, rgb_gain_db=rgb_gain)
time.sleep(1.0 / fps)
print("Restore Delay %d ms" % (time.ticks_ms() - ts))
gain = sensor.get_gain_db()
exposure = sensor.get_exposure_us()
rgb_gain = sensor.get_rgb_gain_db()
print("Gain == %f db" % gain)
print("Exposure == %d us" % exposure)
print("RGB Gain == %f db, %f db, %f db" % (rgb_gain[0], rgb_gain[1], rgb_gain[2]))
clock = time.clock()
while True:
clock.tick()
img = sensor.snapshot()