Ask Your Question

right way to setup cv::VideoCaptureModes

asked 2018-07-30 05:48:05 -0500

nobot gravatar image

In the opencv 3.4.2 documentation here , there is a provision to change the camera modes, so did I implemented as below,

int main(int argc, char argv) {

Mat frame;

VideoCapture cap(0);

    if (!cap.isOpened()) 
        cout << "Cannot open the video cam" << endl;
        return -1;

while (1) {

    cap.set(CAP_MODE_GRAY);   // mode I want

    bool bSuccess =;

     if (!bSuccess)
         cout << "Cannot read a frame from video stream" << endl;           break;

  imshow("simple video",frame);

    if (waitKey(30) == 27) 
        cout << "esc key is pressed by user" << endl;            break; 


its giving the error as

5_graycapmode.cpp:40:30: error: no matching function for call to 'cv::VideoCapture::set(cv::VideoCaptureModes)' cap.set(CAP_MODE_GRAY); ^

In file included from /usr/local/include/opencv2/highgui.hpp:51:0, from /usr/local/include/opencv2/opencv.hpp:68, from 5_graycapmode.cpp:6: /usr/local/include/opencv2/videoio.hpp:778:26: note: candidate: virtual bool cv::VideoCapture::set(int, double) CV_WRAP virtual bool set(int propId, double value); ^~~ /usr/local/include/opencv2/videoio.hpp:778:26: note: candidate expects 2 arguments, 1 provided

Is it probably as my syntax is wrong??

( Its my new account so my replies are kept frozen for 48 hrs)

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted

answered 2018-07-30 06:59:24 -0500

berak gravatar image

you have to use it like:

bool ok = cap.set(CAP_PROP_MODE, CAP_PROP_GRAY);
// and CHECK the return value... !

and then, it may or may not be supported by your os/backend/hw.

edit flag offensive delete link more


also, please do NOT call any set() functions in the loop !

berak gravatar imageberak ( 2018-07-30 07:00:41 -0500 )edit

Question Tools

1 follower


Asked: 2018-07-30 05:48:05 -0500

Seen: 1,358 times

Last updated: Jul 30 '18