I cannot use the webcam as an input device for OpenCV 2.3.1 in Ubuntu 11.04, this code works fine in windows:
#include "cv.h"
#include "highgui.h"
#include <stdio.h>
int main() {
CvCapture* capture = cvCaptureFromCAM(-1);
if( !capture ) {
fprintf( stderr, "ERROR: capture is NULL \n" );
getchar();
return -1;
}
cvNamedWindow( "mywindow", CV_WINDOW_AUTOSIZE );
while( 1 ) {
IplImage* frame = cvQueryFrame( capture );
if( !frame ) {
fprintf( stderr, "ERROR: frame is null...\n" );
getchar();
break;
}
cvShowImage( "mywindow", frame );
if( (cvWaitKey(10) & 255) == 27 ) break;
}
cvReleaseCapture( &capture );
cvDestroyWindow( "mywindow" );
return 0;
}
It returns "ERROR: capture is NULL"
source
share