0
votes

I'm pretty new to OpenCV and I'm trying to get my bearings by looking at, and running, sample code.

One of the sample programs that I was looking at is a program for displaying webcam video. Here are the important lines (the program doesn't execute farther than this):

// Make frame.
CvCapture* capture = cvCaptureFromCAM(0);

if(!capture) {
    printf("Webcam not initialized....");
}
// Display video in frame.

Unfortunately, the if statement always executes. For some reason, capture is not initialized.

Even stranger, when I run the program, it even gives me a GUI to select the webcam that I want to use:

Webcam Selection GUI

However, even after I select the webcam, capture is not initialized!

What does this mean? How do I fix this?

Thanks for any suggestions.

1
Is anything else running that may be using the camera, eg skype ?Martin Beckett
+1 Martin Beckett. I'm sure that this is camera driver issue (or v4l in linux).ArtemStorozhuk

1 Answers

1
votes

It is possible that OpenCV cannot access the webcam until after you select it. In that case, try looping until the webcam is available:

CvCapture *capture = NULL;
do {
    // you could also try passing in CV_CAP_ANY or -1 instead of 0
    capture = cvCaptureFromCAM(0);
} while (!capture);

If this still doesn't work, call cvErrorStr(cvGetErrStatus()) to get a string explaining the error.