Example: 01-Camera/07-Sensor-Control/sensor_save_and_restore_settings.py

# 本作品采用MIT许可证授权。
# 版权所有 (c) 2013-2023 OpenMV LLC。保留所有权利。
# https://github.com/openmv/openmv/blob/master/LICENSE
#
# Sensor Save and Restore Settings
#
# This example shows off how to save and then restore camera settings
# after a sensor reset and/or powerdown.

import sensor
import time

# 将像素格式设置为RGB565 (or GRAYSCALE)
target_pixformat = sensor.RGB565

# 将帧大小设置为QVGA (320x240)
target_framesize = sensor.QVGA

sensor.reset()
sensor.set_pixformat(target_pixformat)
sensor.set_framesize(target_framesize)

# Delay 3 seconds to let the camera auto functions run and measure the fps.
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()

# The sensor should have time now to warm up and adjust to the current environment.
# Grab the settings now before turning off the sensor.

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)

# Disable all settling time delays in the sensor driver code. Turning this off WILL result in
# corrupted images appearing when modifying settings. However, now you can change sensor settings
# in bulk quickly.
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)

# You need to delay before calling snapshot as the image coming out of the camera right now is
# 极有可能存在严重腐败。下方延迟的具体时间取决于应用
# 但您或许应等待一帧。
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()
    # 打印(clock.fps())

results matching ""

    No results matching ""