sensor_save_and_restore_settings.py

# 本作品采用MIT许可证授权。
# 版权所有 (c) 2013-2023 OpenMV LLC。保留所有权利。
# https://github.com/openmv/openmv/blob/master/LICENSE
#
# 传感器设置的保存与恢复
#
# 此示例展示了如何在传感器复位和/或掉电后
# 保存并恢复相机设置。

import csi
import time

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

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

csi0 = csi.CSI()
csi0.reset()
csi0.pixformat(target_pixformat)
csi0.framesize(target_framesize)

# 延时3秒,让相机自动功能运行并测量帧率。
t = time.ticks_ms()
clock = time.clock()
fps = 0
while time.ticks_diff(time.ticks_ms(), t) < 3000:
    clock.tick()
    csi0.snapshot()
    fps = clock.fps()

# 现在传感器应该已有时间预热并适应当前环境。
# 在关闭传感器之前先获取设置。

gain = csi0.gain_db()
exposure = csi0.exposure_us()
rgb_gain = csi0.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")
csi0.shutdown(True)
time.sleep(2)
del csi0

# 禁用传感器驱动代码中的所有稳定时间延时。关闭它必然会在修改设置时
# 出现损坏的图像。但是,现在您可以快速地
# 批量更改传感器设置。

ts = time.ticks_ms()
print("Powering On Sensor")
csi0 = csi.CSI(delays=False)
csi0.reset()
csi0.pixformat(target_pixformat)
csi0.framesize(target_framesize)
csi0.auto_gain(False, gain_db=gain)
csi0.auto_exposure(False, exposure_us=exposure)
csi0.auto_whitebal(False, rgb_gain_db=rgb_gain)

# 您需要延时后再调用snapshot,因为此刻从相机输出的图像
# 极有可能存在严重腐败。下方延迟的具体时间取决于应用
# 但您或许应等待一帧。
time.sleep(1.0 / fps)

print("Restore Delay %d ms" % (time.ticks_ms() - ts))

gain = csi0.gain_db()
exposure = csi0.exposure_us()
rgb_gain = csi0.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 = csi0.snapshot()
    # 打印(clock.fps())

results matching ""

    No results matching ""