Opencv: cvCaptureFromCAM returns NULL

I am in Linux Mint (I don’t know the version) and use the Logitech Orbit AF webcam. I try the following code, but all I get is "ERROR: Capture is null!". Please, help!!!!!

#include<cv.h>
#include<highgui.hpp>
#include<iostream>

using namespace std;

int main() {
    //Data Structure to store cam.
    CvCapture* cap=cvCaptureFromCAM(0);
    //Image variable to store frame
    IplImage* frame;
    //Window to show livefeed
    cvNamedWindow("LiveFeed",CV_WINDOW_AUTOSIZE);
    if(!cap)
    {
        cout << "ERROR: Capture is null!\n";
    }
    while(1)
    {
        //Load the next frame
        frame=cvQueryFrame(cap);
        //If frame is not loaded break from the loop
        if(!frame)
            break;
        //Show the present frame
        cvShowImage("LiveFeed",frame);
        //Escape Sequence
        char c=cvWaitKey(33);
        //If the key pressed by user is Esc(ASCII is 27) then break out of the loop
        if(c==27)
           break;
    }
    //CleanUp
    cvReleaseCapture(&cap);
    cvDestroyAllWindows(); 

}

+3
source share
2 answers

When this call returns NULL:

CvCapture* cap = cvCaptureFromCAM(0);
if (!cap)
{
    // print error and exit
    cout << "ERROR: Capture is null!\n";
    return -1;
}

this means that no devices were found in the index 0. Try passing CV_CAP_ANYinstead, so that OpenCV chooses a valid index number for you.

If this does not work, your camera may not be supported by OpenCV. Try to find in this list .

+2
source

, opencv (2.4.9). 2.3, .

0