2011-11-02 13 views
5

no puedo utilizar la cámara web como dispositivo de entrada para OpenCV 2.3.1 en Ubuntu 11.04, este código funciona bien en las ventanas:OpenCV no puede encontrar el dispositivo de vídeo

#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; 
} 

devuelve "ERROR: captura es NULL"

+0

Mi cámara web es/dev/video0 – Maysam

+0

¿Puede capturar cuadros con otra aplicación V4L (por ejemplo, Camorama)? Solo para asegurarse de que tiene todos los requisitos necesarios instalados y la cámara es realmente compatible. –

+0

Sí, puedo, Camorama funciona bien – Maysam

Respuesta

4

Encontré la solución, necesito instalar libv4l-0 y libv4l-dev luego compilar OpenCV con USE_V4L=ON.

Cuestiones relacionadas