2011-11-02 100 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。