Configuring camera properties in new OCV 2.4.3

后端 未结 3 1983
借酒劲吻你
借酒劲吻你 2021-01-15 06:38

I may just be googling wrong, but I cannot find out a way (read function) to change properties of camera in the new Open CV. I need to disable auto exposure

相关标签:
3条回答
  • 2021-01-15 06:58

    so, there's your VideoCapture:

    VideoCapture cap(0);
    

    now you could try to set or get properties:

    //may work or not, highly driver/impl specific.
    cap.set(CV_CAP_PROP_AUTO_EXPOSURE, 0 ); 
    double exposure = cap.get(CV_CAP_PROP_AUTO_EXPOSURE); 
    

    sometimes you can even acces the drivers config dialog this way:

    cap.set(CV_CAP_PROP_SETTINGS , 1 );
    

    those constants are in highgui_c.h, around l 333

    0 讨论(0)
  • 2021-01-15 07:06

    You can use the OpenCV API to do this using VideoCapture::Set(). Here is an example of how to set the exposure manually in Python:

    import cv2
    
    cap = cv2.VideoCapture(0)
    cap.set(cv2.CAP_PROP_EXPOSURE,-4)
    
    while(True):
        ret, frame = cap.read()
    
        cv2.imshow('frame',frame)
        if cv2.waitKey(1) & 0xFF == ord('q'):
            break
    
    cap.release()
    cv2.destroyAllWindows()
    

    Here are the notes I have about the exposure time for each frame. Though I believe they are camera specific, they give you a good idea.

    -1  640 ms
    -2  320 ms
    -3  160 ms
    -4  80 ms
    -5  40 ms
    -6  20 ms
    -7  10 ms
    -8  5 ms
    -9  2.5 ms
    -10 1.25 ms
    -11 650 µs
    -12 312 µs
    -13 150 µs
    

    The same function has settings for GAIN and many other values, though I have not tried them.

    A bit more discussion at Setting Manual Exposure in OpenCV

    0 讨论(0)
  • 2021-01-15 07:15

    This is an old question but I want to add a solution to this.

    opencv calls underlying v4l methods to query frames, set/get camera properties etc. And the problem is, the calls are not complete. Also for some reason, the library calls v4l methods instead of v4l2 ones. Similar issue here. It is solved through modifying opencv code, it seems.

    I also checked if opencv can set a property supported in v4l2 -like "manual exposure", "or exposure auto priority". It couldn't. I played around v4l2 to solve this:

    #include <libv4l2.h>
    #include <linux/videodev2.h>
    #include <sys/ioctl.h>
    #include <fcntl.h>
    
    // open capture
    int descriptor = v4l2_open("/dev/video0", O_RDWR);
    
    // manual exposure control
    v4l2_control c;
    c.id = V4L2_CID_EXPOSURE_AUTO;
    c.value = V4L2_EXPOSURE_MANUAL;
    if(v4l2_ioctl(descriptor, VIDIOC_S_CTRL, &c) == 0)
        cout << "success";
    
    // auto priority control
    c.id = V4L2_CID_EXPOSURE_AUTO_PRIORITY;
    c.value = 0;
    if(v4l2_ioctl(descriptor, VIDIOC_S_CTRL, &c) == 0)
        cout << "success";
    

    You can then work with opencv.

    Full list of camera controls are here.

    0 讨论(0)
提交回复
热议问题