I am on Ubuntu 10.10 and trying to capture video from a ps3eye camera, afaik OpenCV uses v4l for capturing from webcams, gucview, cheese, vlc all can access and use the camera but when using opencv to capture from it I get blank frames.
/**
* Display video from webcam
*
* Author Nash
* License GPL
* Website http://nashruddin.com
*/
//gcc test.c -I /usr/include/opencv/ -L /usr/lib/ -lcv -lhighgui
#include <stdio.h>
#include "cv.h"
#include "highgui.h"
int main( int argc, char **argv )
{
CvCapture *capture = 0;
IplImage *frame = 0;
int key = 0;
/* initialize camera */
capture = cvCaptureFromCAM( -1 );
/* always check */
if ( !capture ) {
fprintf( stderr, "Cannot open initialize webcam!\n" );
return 1;
}
/* create a window for the video */
cvNamedWindow( "result", CV_WINDOW_AUTOSIZE );
开发者_如何学Python while( key != 'q' ) {
/* get a frame */
frame = cvQueryFrame( capture );
/* always check */
if( !frame ) break;
/* display current frame */
cvShowImage( "result", frame );
/* exit if user press 'q' */
key = cvWaitKey( 1 );
}
/* free memory */
cvDestroyWindow( "result" );
cvReleaseCapture( &capture );
return 0;
}
精彩评论