如何在 OpenCV (Python) 中启用/禁用手动白平衡
在 Linux 上使用 OpenCV,如果你有连接 V4L2 设备(如 USB 摄像头)的视频设备:
open_camera.py
camera = cv2.VideoCapture(0)你通常可以使用以下命令为任何摄像头启用自动白平衡(= 禁用手动白平衡)
enable_auto_wb.py
camera.set(cv2.CAP_PROP_AUTO_WB, 1.0) # 启用自动白平衡或使用以下命令禁用自动白平衡(= 启用手动白平衡)
disable_auto_wb.py
camera.set(cv2.CAP_PROP_AUTO_WB, 0.0) # 禁用自动白平衡当禁用自动白平衡时,你还应该设置手动白平衡温度 - 有关更多详细信息,请参阅我们的文章如何在 OpenCV (Python) 中设置手动白平衡温度。
对于 V4L2 摄像头,正如我们之前关于 OpenCV 参数映射到 V4L2 参数的文章所述,CAP_PROP_AUTO_WB 映射到 V4L2_CID_AUTO_WHITE_BALANCE,在 v4l2-ctl -d /dev/video0 --all 中显示为 white_balance_temperature_auto。因此,你可以通过查看 v4l2-ctl -d /dev/video0 --all 的 white_balance_temperature_auto 部分来轻松验证例如禁用自动白平衡是否适用于你的 V4L2 摄像头(如任何 USB 摄像头):
v4l2ctl-output.txt
white_balance_temperature_auto 0x0098090c (bool) : default=1 value=0If this post helped you, please consider buying me a coffee or donating via PayPal to support research & publishing of new posts on TechOverflow