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

# 本作品采用MIT许可证授权。
# 版权所有 (c) 2013-2023 OpenMV LLC。保留所有权利。
# https://github.com/openmv/openmv/blob/master/LICENSE
#
# 传感器手动增益控制
#
# 此示例展示了如何控制相机传感器的
# 手动增益与自动增益控制运行。

# What's the difference between gain and exposure control?
#
# Well, by increasing the exposure time for the image you're getting more
# 相机上的光线。这为您提供了最佳的信噪比。
# in general always want to increase the expsoure time... except, when you
# increase the exposure time you decrease the maximum possible frame rate
# and if anything moves in the image it will start to blur more with a
# higher exposure time. Gain control allows you to increase the output per
# pixel using analog and digital multipliers... however, it also amplifies
# noise. So, it's best to let the exposure increase as much as possible
# and then use gain control to make up any remaining ground.

import sensor
import time

# 更改此值以调整增益。尝试10.0/0/0.1等。
GAIN_SCALE = 1.0

sensor.reset()  # 重置并初始化传感器。
sensor.set_pixformat(sensor.RGB565)  # 将像素格式设置为RGB565 (or GRAYSCALE)
sensor.set_framesize(sensor.QVGA)  # 将帧大小设置为QVGA (320x240)

# 打印初始增益以进行比较。
print("Initial gain == %f db" % sensor.get_gain_db())

sensor.skip_frames(time=2000)  # 等待设置生效。
clock = time.clock()  # 创建一个时钟对象来跟踪FPS。

# 你必须关闭自动曝光控制和自动白平衡
# 否则它们会改变图像曝光以撤销任何增益设置
# 你所设定的...
sensor.set_auto_exposure(False)
sensor.set_auto_whitebal(False)
# 需要让上述设置生效...
sensor.skip_frames(time=500)

current_gain_in_decibels = sensor.get_gain_db()
print("Current Gain == %f db" % current_gain_in_decibels)

# 自动增益控制 (AGC) 默认启用。调用以下函数
# 禁用传感器自动增益控制。额外的 "gain_db"
# 参数在 AGC 禁用后覆盖自动增益值。
sensor.set_auto_gain(False, gain_db=current_gain_in_decibels * GAIN_SCALE)

print("New gain == %f db" % sensor.get_gain_db())
# sensor.get_gain_db() 返回相机传感器增益分贝的确切值。
# 然而,这可能与命令的值不同,因为
# 传感器代码将增益转换为小增益值和大增益值
# 无法接受所有可能的值...

# 如果你想重新启用自动增益,请执行:sensor.set_auto_gain(True)
# 请注意,相机传感器将根据需要更改增益。

# 执行:sensor.set_auto_gain(False)
# 只是禁用增益值更新,但不会改变增益
# 相机传感器确定的值是好的。

while True:
    clock.tick()  # 更新FPS时钟。
    img = sensor.snapshot()  # 拍照并返回图像。
    print(clock.fps())  # 注意:OpenMV摄像头在连接至IDE时运行速度会降低约一半。
    # 断开连接后,帧率应会提升。

results matching ""

    No results matching ""