1
votes

I am using OpenCV2.2 in Ubuntu 11.04. Using code::blocks 10.05 IDE. Testing the webcam with a simple code in openCV to capture video from the webcam. But, cvCreateCameraCapture(index) is always returning null(showing 0 error, 0 warning). I have checked for index {-5 to +5}. The inbuilt webcam of my Acer Aspire 4736z is working fine with Cheese. lsusb showing:

Bus 002 Device 002: ID 04f2:b044 Chicony Electronics Co., Ltd Acer CrystalEye Webcam

means driver is installed.

grep -i v4l /var/log/udev returns

ID_V4L_VERSION=2

ID_V4L_PRODUCT=Video WebCam

ID_V4L_CAPABILITIES=:capture:

DEVLINKS=/dev/v4l/by-id/usb-Chicony_Electronics_Co.__Ltd._Video_WebCam_SN0001-video-index0 /dev/v4l/by-path/pci-0000:00:1d.7-usb-0:4:1.0-video-index0

Also followed this: cvCreateCameraCapture returns null but got nothing.

Code is:

int main(int argc, char**argv)   
{
    IplImage *img;    

    char ch;    

    int c;     

    CvCapture *capture= cvCreateCameraCapture(0);    

    cvNamedWindow("Example1",CV_WINDOW_AUTOSIZE);    

    if(!capture)    
        printf("Camera Not Initialized");return 0;

    while (capture)
    {    
        img=cvQueryFrame(capture);

        cvShowImage("Example1",img);

        ch=cvWaitKey(33);

        if(ch==32)    
            break;    
    }

    cvReleaseImage(&img);

    cvDestroyWindow("Example1");    
}    

Output Window: Camera Not Initialized

Process returned 0(0X0) execution time:0.155s

press enter to continue.

Please Help me what is the problem, why the camera not working?

1
Can you access and control the camera with v4l2ucp? Also, did you compile OpenCV yourself with all the necessary ffmpeg dependencies?mevatron

1 Answers

0
votes

try recompiling OpenCV making sure you meet all the dependencies (see here).

Plus, use the newer

CvCapture* cam = cvCaptureFromCAM(CV_CAP_ANY);