sensor_save_and_restore_settings.py

# この作品はMITライセンスの下で提供されています。
# Copyright (c) 2013-2023 OpenMV LLC. 全著作権所有。
# https://github.com/openmv/openmv/blob/master/LICENSE
#
# センサー設定の保存と復元
#
# この例では、センサーのリセットや電源断の後に
# カメラの設定を保存してから復元する方法を示します。

import csi
import time

# ピクセルフォーマットをRGB565(またはGRAYSCALE)に設定します
target_pixformat = csi.RGB565

# フレームサイズをQVGA(320x240)に設定します
target_framesize = csi.QVGA

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

# カメラの自動機能を動作させてFPSを計測するため、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を呼び出す前に待機する必要があります。現在カメラから出てくる画像は
# 非常に乱れている可能性が高いためです。以下で待機する具体的な時間はアプリケーションに
# 依存します。ただし、少なくとも1フレーム分は待つべきでしょう。
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()
    # print(clock.fps())

results matching ""

    No results matching ""