Example: 01-Camera/07-Sensor-Control/sensor_exposure_control.py
# 本作品采用MIT许可证授权。
# 版权所有 (c) 2013-2023 OpenMV LLC。保留所有权利。
# https://github.com/openmv/openmv/blob/master/LICENSE
#
# Sensor Exposure Control
#
# This example shows off how to cotnrol the camera sensor's
# exposure manually versus letting auto exposure control run.
# 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
# Change this value to adjust the exposure. Try 10.0/0.1/etc.
EXPOSURE_TIME_SCALE = 1.0
sensor.reset() # 重置并初始化传感器。
sensor.set_pixformat(sensor.RGB565) # 将像素格式设置为RGB565 (or GRAYSCALE)
sensor.set_framesize(sensor.QVGA) # 将帧大小设置为QVGA (320x240)
# Print out the initial exposure time for comparison.
print("Initial exposure == %d" % sensor.get_exposure_us())
sensor.skip_frames(time=2000) # 等待设置生效。
clock = time.clock() # 创建一个时钟对象来跟踪FPS。
# 你必须关闭自动增益控制和自动白平衡
# 否则它们会调整图像增益来抵消任何曝光设置
# 你所设定的...
sensor.set_auto_gain(False)
sensor.set_auto_whitebal(False)
# 需要让上述设置生效...
sensor.skip_frames(time=500)
current_exposure_time_in_microseconds = sensor.get_exposure_us()
print("Current Exposure == %d" % current_exposure_time_in_microseconds)
# 自动曝光控制(AEC)默认启用。调用以下函数
# 将禁用传感器自动曝光控制。额外的"exposure_us"
# 参数会在AEC禁用后覆盖自动曝光值
sensor.set_auto_exposure(
False, exposure_us=int(current_exposure_time_in_microseconds * EXPOSURE_TIME_SCALE)
)
print("New exposure == %d" % sensor.get_exposure_us())
# sensor.get_exposure_us()返回精确的相机传感器曝光时间
# (微秒单位)。但这个数值可能与指令值不同
# 因为传感器代码会将微秒曝光时间转换为
# 行/像素/时钟时间,无法完美匹配微秒...
# 如需重新启用自动曝光:sensor.set_auto_exposure(True)
# 注意相机传感器将自行调整曝光时间
# 执行:sensor.set_auto_exposure(False)
# 仅禁用曝光值更新,不改变当前曝光
# 相机传感器确定的值是好的。
while True:
clock.tick() # 更新FPS时钟。
img = sensor.snapshot() # 拍照并返回图像。
print(clock.fps()) # 注意:OpenMV摄像头在连接至IDE时运行速度会降低约一半。
# 断开连接后,帧率应会提升。