简体   繁体   中英

Displaying a video using OpenCV 2.4.1

Hi i tried to display a video using webcam using following basic commands in opencv 2.4.1 :-

int main()

{ cv::Mat san;

  cv::VideoCapture san_cap(0);

  while(1)
  {
    san_cap.read(san);

    cv::imshow("gp",san);

    if(cv::waitKey(0) >=0)

      break;
  }

   return 1;

  }

during compilation i dont get any error but while running my solution my output video stucked on a fixed frame and in my console i was having following error :-

VIDIOC_QUERYMENU: Invalid argument

on line by line debbuging my code i found out im getting error in this particular line

if(cv::waitKey(0) >= 0)

what can be the error in this line???

I don't know what you are trying to do with the cv::waitKey() but I think your example should work if you change it to this. As mentioned the waitKey should be set to something like 10 and you should always check if the videoCapture is actually open. If it can not be opened it is a problem with your hardware/driver/os/OpenCV install.

int main() {

    int waitKeyValue = 10;
    cv::Mat san;

    cv::VideoCapture san_cap(0);
    if (san_cap.isOpened()) {
        while (1) {
            san_cap.read(san);
            cv::imshow("gp", san);
            int key = cv::waitKey(waitKeyValue);
            if(key!=-1)cout<<key<<endl;
            if (key == 27 || key == 1048586) {
                if (waitKeyValue == 10)waitKeyValue = 0;
                else waitKeyValue = 10;
            }
        }
    } else cout << "videoCapture not working" << endl;
    return 1;

}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM