I'm struggling with connecting my webcam in OpenCV. My laptop's webcam in Windows 7 64-bit works properly. But if I connect another webcam, the code doesn't work at all:
capWebcam = cvCaptureFromCAM(0);
if(capWebcam == NULL) {
printf("error: capture is NULL \n");
getchar();
return(-1);
}
Since there isn't any webcam, it returns the message error. I disabled laptop webcam, and it worked, but I'm getting black screen.
I tried two webcams, namely Logitech HD Pro C920 and LifeCam Cinema from Microsoft. This is the line responsible to get the cam:
CvCapture* mycapWebcam = cvCaptureFromCAM(0);
I changed the 0 to another value (0-10) and this is information about this structure:
CvCapture* cvCaptureFromCAM(int index)
Initializes capturing a video from a camera.
Parameter: index – Index of the camera to be used. If there is only one camera or it does not matter what camera is used -1 may be passed.
The function cvCaptureFromCAM() allocates and initializes the CvCapture structure for reading a video stream from the camera. Currently two camera interfaces can be used on Windows: Video for Windows (VFW) and Matrox Imaging Library (MIL); and two on Linux: V4L and FireWire (IEEE1394).
To release the structure, use ReleaseCapture.
How can I fix this problem?