我正在尝试使用cv2.VideoCapture实现C920 Logitech摄像头,但无法在关闭自动对焦的情况下将摄像头固定到固定焦距
    我尝试使用@jakub在本文(Set WebCamera focus with OpenCv in Raspberry Pi)中提到的子流程功能,但是Logitech cam似乎仍在做它想做的事情,并且忽略了手动设置。如下面的代码所示,它似乎接受该设置,但在程序运行后仍继续尝试自动对焦

    1. lc_vs = cv2.VideoCapture(1)
    2. lc_vs.set(3, 1280) #set width to 1280
    3. lc_vs.set(4, 720) #set height to 720
    4. time.sleep(2)
    5. #set Logitech settings below
    6. subprocess.call(['v4l2-ctl -d /dev/video1 --set-ctrl=exposure_auto_priority=0'], shell=True)
    7. time.sleep(0.1)
    8. subprocess.call(['v4l2-ctl -d /dev/video1 --set-ctrl=exposure_auto=1'], shell=True)
    9. time.sleep(0.1)
    10. subprocess.call(['v4l2-ctl -d /dev/video1 --set-ctrl=exposure_absolute=25'], shell=True)
    11. time.sleep(0.1)
    12. subprocess.call(['v4l2-ctl -d /dev/video1 --set-ctrl=zoom_absolute=100'], shell=True)
    13. time.sleep(0.1)
    14. subprocess.call(['v4l2-ctl -d /dev/video1 --set-ctrl=white_balance_temperature_auto=0'], shell=True)
    15. time.sleep(0.1)
    16. subprocess.call(['v4l2-ctl -d /dev/video1 --set-ctrl=white_balance_temperature=5500'], shell=True)
    17. time.sleep(0.1)
    18. subprocess.call(['v4l2-ctl -d /dev/video1 --set-ctrl=focus_auto=0'], shell=True)
    19. time.sleep(0.2)
    20. subprocess.call(['v4l2-ctl -d /dev/video1 --set-ctrl=focus_absolute=50'], shell=True)
    21. time.sleep(0.2)
    22. subprocess.call(['v4l2-ctl -d /dev/video1 --set-ctrl=sharpness=128'], shell=True)
    23. time.sleep(0.2)
    24. #check logitech settings
    25. subprocess.call(['v4l2-ctl -d /dev/video1 -l'], shell=True)

    然后,它向我提供了下面的输出,这似乎表明自动对焦已关闭,固定焦距为50(测试为理想值)。(见最后第二行和第三行)

    1. brightness 0x00980900 (int) : min=0 max=255 step=1 default=128 value=128
    2. contrast 0x00980901 (int) : min=0 max=255 step=1 default=128 value=128
    3. saturation 0x00980902 (int) : min=0 max=255 step=1 default=128 value=128
    4. white_balance_temperature_auto 0x0098090c (bool) : default=1 value=0
    5. gain 0x00980913 (int) : min=0 max=255 step=1 default=0 value=0
    6. power_line_frequency 0x00980918 (menu) : min=0 max=2 default=2 value=2
    7. white_balance_temperature 0x0098091a (int) : min=2000 max=6500 step=1 default=4000 value=5500
    8. sharpness 0x0098091b (int) : min=0 max=255 step=1 default=128 value=128
    9. backlight_compensation 0x0098091c (int) : min=0 max=1 step=1 default=0 value=0
    10. exposure_auto 0x009a0901 (menu) : min=0 max=3 default=3 value=1
    11. exposure_absolute 0x009a0902 (int) : min=3 max=2047 step=1 default=250 value=25
    12. exposure_auto_priority 0x009a0903 (bool) : default=0 value=0
    13. pan_absolute 0x009a0908 (int) : min=-36000 max=36000 step=3600 default=0 value=0
    14. tilt_absolute 0x009a0909 (int) : min=-36000 max=36000 step=3600 default=0 value=0
    15. focus_absolute 0x009a090a (int) : min=0 max=250 step=5 default=0 value=50
    16. focus_auto 0x009a090c (bool) : default=1 value=0
    17. zoom_absolute 0x009a090d (int) : min=100 max=500 step=1 default=100 value=100

    然而,罗技摄像头似乎仍然试图在每次有新的东西进入画面时手动对焦。从流中读取帧的最终代码是:

    1. while true:
    2. ret, lc_frame = lc_vs.read()

    非常感谢您的任何建议。多谢各位

    ref
    https://www.cnpython.com/qa/1446218