2011-11-02 97 views
5

我无法在Ubuntu 11.04使用网络摄像头作为输入设备的OpenCV 2.3.1,该代码工作正常的Windows:OpenCV中找不到视频设备

#include "cv.h" 
#include "highgui.h" 
#include <stdio.h> 

// A Simple Camera Capture Framework 
int main() { 

    CvCapture* capture = cvCaptureFromCAM(-1); 
    if(!capture) { 
    fprintf(stderr, "ERROR: capture is NULL \n"); 
    getchar(); 
    return -1; 
    } 

    // Create a window in which the captured images will be presented 
    cvNamedWindow("mywindow", CV_WINDOW_AUTOSIZE); 

    // Show the image captured from the camera in the window and repeat 
    while(1) { 

    // Get one frame 
    IplImage* frame = cvQueryFrame(capture); 
    if(!frame) { 
     fprintf(stderr, "ERROR: frame is null...\n"); 
     getchar(); 
     break; 
    } 

    cvShowImage("mywindow", frame); 
    // Do not release the frame! 

    //If ESC key pressed, Key=0x10001B under OpenCV 0.9.7(linux version), 
    //remove higher bits using AND operator 
    if((cvWaitKey(10) & 255) == 27) break; 
    } 

    // Release the capture device housekeeping 
    cvReleaseCapture(&capture); 
    cvDestroyWindow("mywindow"); 
    return 0; 
} 

它返回“ERROR:捕捉NULL”

+0

我的摄像头是/ dev/video0 – Maysam

+0

您可以用另一个V4L应用程序(例如Camorama)捕获帧吗?只是为了确保您已经安装了所有需要的要求,并且实际上支持了凸轮。 –

+0

是的,我可以,Camorama工作正常 – Maysam

回答

4

我找到了解决方案,我需要安装libv4l-0libv4l-dev然后用USE_V4L=ON编译OpenCV。