Accessing to webcam video?
I'm testing out some code I found to capture the web cam video stream, it's quite different from what I used to do for achieving the same but it's supposed to be the appropiate way for doing it.
This is the way I used to do:
CvCapture* capture;
IplImage* frame = 0;
while (true)
{
//Read the video stream
capture = cvCaptureFromCAM(1);
if (! capture) break;
frame = cvQueryFrame(capture);
//Create a window to display
cvNamedWindow("Te estas viendo", CV_WINDOW_NORMAL|CV_WINDOW_KEEPRATIO);
cvShowImage("Te estas viendo", frame);
int c = cvWaitKey(10);
if ( (char)c == 27 ) break;
}
//Clean and release resources
cvReleaseImage(&frame);
cvDestroyAllWindows();
This is the testing code:
VideoCapture camera;
camera.open(cameraNumber);
namedWindow("output");
if (!camera.isOpened()) {
cerr << "ERROR: Could not access the camera or video!" <<endl;
return -1;
}
while (true) {
// Grab the next camera frame.
cv::Mat cameraFrame;
camera >> cameraFrame;
if (cameraFrame.empty()) {
std::cerr << "ERROR: Couldn't grab a camera frame." <<
std::endl;
return -1;
}
imshow("output", cameraFrame);
waitKey(10);
}
I'm not getting the first error line, so it's supposed to be opening the camera, but always failing at grabbing camera frames.
please get the braces right, as already proposed on SO [ also, that wouldn't even compile, so can't be the exact code you're actually using ]
I did, @berak, I simply did a bad copy paste of question from SO.
yes, but, correcting that will help you. so please just edit.