Video capture on MacBook
I'm attempting to access the build-in camera on a MacBook Pro (running OS X 10.8.3, with OpenCV 2.4.6.1) with code I found elsewhere:
int main( int argc, const char** argv ) {
CvCapture* capture = NULL;
if ((capture = cvCaptureFromCAM(-1)) == NULL)
{
std::cerr << "!!! ERROR: vCaptureFromCAM No camera found\n";
return -1;
}
cvNamedWindow("webcam", CV_WINDOW_AUTOSIZE);
cvMoveWindow("webcam", 50, 50);
IplImage* src = NULL;
for (;;)
{
if ((src = cvQueryFrame(capture)) == NULL)
{
std::cerr << "!!! ERROR: vQueryFrame\n";
break;
}
cvShowImage("webcam", &src);
}
cvReleaseCapture(&capture);
return 0;
}
The camera appears to be found, the green light goes on, yet the frame returned by cvQueryFrame is always NULL. What might be wrong here?
Thanks!
Try using the C++ interface and the Mat type of elements instead of the old depricated C style API. Look into this nice tutorial to get the basics of image reading and displaying.
Also try the OpenCV 2.4.6 (not
.1
).