Example: 01-Camera/07-Sensor-Control/sensor_manual_whitebal_control.py
# 本作品采用MIT许可证授权。
# 版权所有 (c) 2013-2023 OpenMV LLC。保留所有权利。
# https://github.com/openmv/openmv/blob/master/LICENSE
#
# 传感器手动白平衡控制
#
# 此示例展示了如何控制相机传感器的
# 手动设置白平衡增益,而不是让 AWB 控制运行。
# 白色 balance is achieve by adjusting R/G/B gain values
# such that the average color of the image is gray. The
# automatic white balance (AWB) algorithm does this for
# you but usually ends up with a different result each
# time you turn the camera on making it hard to get
# color tracking settings right. By manually recording
# the gain values you like and then forcing them to
# the sensor on startup you can control the colors
# the camera sees.
import sensor
import time
sensor.reset() # 重置并初始化传感器。
sensor.set_pixformat(sensor.RGB565) # 将像素格式设置为RGB565 (or GRAYSCALE)
sensor.set_framesize(sensor.QVGA) # 将帧大小设置为QVGA (320x240)
sensor.skip_frames(time=2000) # 等待设置生效。
clock = time.clock() # 创建一个时钟对象来跟踪FPS。
# You can control the white balance gains here. The first value is the
# R gain in db, and then the G gain in db, followed by the B gain in db.
#
# Uncomment the below line with gain values you like (get them from the print out).
#
# sensor.set_auto_whitebal(False, rgb_gain_db = (0.0, 0.0, 0.0))
# Note: Putting (0.0, 0.0, 0.0) for the gain results in something close to zero
# coming out. Do not expect the exact value going in to be equal to the value
# coming out.
while True:
clock.tick() # 更新FPS时钟。
img = sensor.snapshot() # 拍照并返回图像。
print(clock.fps(), sensor.get_rgb_gain_db()) # Prints the AWB current RGB gains.