【问题标题】:How to set camera to auto-exposure with OpenCV 3.4.2?如何使用 OpenCV 3.4.2 将相机设置为自动曝光?
【发布时间】:2019-05-01 22:12:07
【问题描述】:

我正在使用PS-Eye-3 相机、libusbPSEye driver、OpenCV 3.4.2 和 Windows 10 上的 Visual Studio 2015 / C++。

我可以使用以下代码将相机的曝光设置为任何值:

cv::VideoCapture *cap;  
...
cap = new cv::VideoCapture(0);
cap->set(CV_CAP_PROP_EXPOSURE, exposure); // exposure = [0, 255]

现在我也想切换到自动曝光。如何将相机设置为自动曝光模式?

我尝试了以下方法:

cap->set(CV_CAP_PROP_EXPOSURE, 0);       // not working
cap->set(CV_CAP_PROP_EXPOSURE, -1);      // not working
cap->set(CV_CAP_PROP_AUTO_EXPOSURE, 1);  // not working, exposure stays fixed
cap->set(CV_CAP_PROP_AUTO_EXPOSURE, 0);  // not working, exposure stays fixed
cap->set(CV_CAP_PROP_AUTO_EXPOSURE, -1); // not working, exposure stays fixed

有什么想法吗?

【问题讨论】:

    标签: c++ opencv camera exposure


    【解决方案1】:

    我想我终于找到了解决方案,至少对于我的问题,

    capture = cv2.VideoCapture(id)
    capture.set(cv2.CAP_PROP_AUTO_EXPOSURE, 3) # auto mode
    capture.set(cv2.CAP_PROP_AUTO_EXPOSURE, 1) # manual mode
    capture.set(cv2.CAP_PROP_EXPOSURE, desired_exposure_value)
    
    

    我必须先将 auto_exposure 设置为 3(自动模式)
    然后我必须将其设置为 1(手动模式)
    然后我可以设置手动曝光


    您也可以使用 shell 进行设置
    列出可用选项

    video_id=1
    v4l2-ctl --device /dev/video$video_id -l
    

    用python设置它们
    def set_manual_exposure(dev_video_id, exposure_time):
        commands = [
            ("v4l2-ctl --device /dev/video"+str(id)+" -c exposure_auto=3"),
            ("v4l2-ctl --device /dev/video"+str(id)+" -c exposure_auto=1"),
            ("v4l2-ctl --device /dev/video"+str(id)+" -c exposure_absolute="+str(exposure_time))
        ]
        for c in commands: 
            os.system(c)
    # usage 
    set_manual_exposure(1, 18)
    

    【讨论】:

      【解决方案2】:

      这取决于您使用的捕获 api。如果您使用的是 CAP_V4L2,则自动曝光设置为“开”(值为 3)和“关”(值为 1)。

      在终端输入v4l2-ctl -l可以找到所有可设置的值。

      我认为对于 OpenCV

      【讨论】:

        【解决方案3】:

        试试 cap->set(CV_CAP_PROP_AUTO_EXPOSURE, X); 其中 X 是与相机相关的值,例如 0.25 或 0.75。 对于类似的问题,请参阅讨论: https://github.com/opencv/opencv/issues/9738

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2021-05-17
          • 2012-05-06
          • 1970-01-01
          • 1970-01-01
          • 2014-02-10
          • 1970-01-01
          • 2016-11-01
          • 1970-01-01
          相关资源
          最近更新 更多