Reputation: 30
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 i m getting error in this particular line
if(cv::waitKey(0) >= 0)
what can be the error in this line???
Upvotes: 0
Views: 5371
Reputation: 1531
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;
}
Upvotes: 1