我正在尝试使用cv2.VideoCapture实现C920 Logitech摄像头,但无法在关闭自动对焦的情况下将摄像头固定到固定焦距
我尝试使用@jakub在本文(Set WebCamera focus with OpenCv in Raspberry Pi)中提到的子流程功能,但是Logitech cam似乎仍在做它想做的事情,并且忽略了手动设置。如下面的代码所示,它似乎接受该设置,但在程序运行后仍继续尝试自动对焦
lc_vs = cv2.VideoCapture(1)
lc_vs.set(3, 1280) #set width to 1280
lc_vs.set(4, 720) #set height to 720
time.sleep(2)
#set Logitech settings below
subprocess.call(['v4l2-ctl -d /dev/video1 --set-ctrl=exposure_auto_priority=0'], shell=True)
time.sleep(0.1)
subprocess.call(['v4l2-ctl -d /dev/video1 --set-ctrl=exposure_auto=1'], shell=True)
time.sleep(0.1)
subprocess.call(['v4l2-ctl -d /dev/video1 --set-ctrl=exposure_absolute=25'], shell=True)
time.sleep(0.1)
subprocess.call(['v4l2-ctl -d /dev/video1 --set-ctrl=zoom_absolute=100'], shell=True)
time.sleep(0.1)
subprocess.call(['v4l2-ctl -d /dev/video1 --set-ctrl=white_balance_temperature_auto=0'], shell=True)
time.sleep(0.1)
subprocess.call(['v4l2-ctl -d /dev/video1 --set-ctrl=white_balance_temperature=5500'], shell=True)
time.sleep(0.1)
subprocess.call(['v4l2-ctl -d /dev/video1 --set-ctrl=focus_auto=0'], shell=True)
time.sleep(0.2)
subprocess.call(['v4l2-ctl -d /dev/video1 --set-ctrl=focus_absolute=50'], shell=True)
time.sleep(0.2)
subprocess.call(['v4l2-ctl -d /dev/video1 --set-ctrl=sharpness=128'], shell=True)
time.sleep(0.2)
#check logitech settings
subprocess.call(['v4l2-ctl -d /dev/video1 -l'], shell=True)
然后,它向我提供了下面的输出,这似乎表明自动对焦已关闭,固定焦距为50(测试为理想值)。(见最后第二行和第三行)
brightness 0x00980900 (int) : min=0 max=255 step=1 default=128 value=128
contrast 0x00980901 (int) : min=0 max=255 step=1 default=128 value=128
saturation 0x00980902 (int) : min=0 max=255 step=1 default=128 value=128
white_balance_temperature_auto 0x0098090c (bool) : default=1 value=0
gain 0x00980913 (int) : min=0 max=255 step=1 default=0 value=0
power_line_frequency 0x00980918 (menu) : min=0 max=2 default=2 value=2
white_balance_temperature 0x0098091a (int) : min=2000 max=6500 step=1 default=4000 value=5500
sharpness 0x0098091b (int) : min=0 max=255 step=1 default=128 value=128
backlight_compensation 0x0098091c (int) : min=0 max=1 step=1 default=0 value=0
exposure_auto 0x009a0901 (menu) : min=0 max=3 default=3 value=1
exposure_absolute 0x009a0902 (int) : min=3 max=2047 step=1 default=250 value=25
exposure_auto_priority 0x009a0903 (bool) : default=0 value=0
pan_absolute 0x009a0908 (int) : min=-36000 max=36000 step=3600 default=0 value=0
tilt_absolute 0x009a0909 (int) : min=-36000 max=36000 step=3600 default=0 value=0
focus_absolute 0x009a090a (int) : min=0 max=250 step=5 default=0 value=50
focus_auto 0x009a090c (bool) : default=1 value=0
zoom_absolute 0x009a090d (int) : min=100 max=500 step=1 default=100 value=100
然而,罗技摄像头似乎仍然试图在每次有新的东西进入画面时手动对焦。从流中读取帧的最终代码是:
while true:
ret, lc_frame = lc_vs.read()
非常感谢您的任何建议。多谢各位