Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //
- // Example showing how to connect to a webcam and capture
- // video frames
- // you may need to chanve the openCV library paths to suit your setup.
- #include </usr/include/opencv/cv.h>
- #include </usr/include/opencv/highgui.h>
- #include </usr/include/opencv/cxcore.h>
- #include "stdio.h"
- #include "string.h" int main(int argc, char ** argv)
- {
- CvCapture * pCapture = 0;
- IplImage * pVideoFrame = 0;
- int i;
- char filename[50]; //returns the number of available cameras in the system
- // int ncams = cvcamGetCamerasCount( );
- // fprintf(stderr, "Number of cameras: %d\n", ncams); // Initialize video capture
- // pCapture = cvCaptureFromCAM( CV_CAP_ANY );
- pCapture = cvCaptureFromCAM( -1 );
- if( !pCapture )
- {
- fprintf(stderr, "failed to initialize video capture\n");
- return -1;
- } // Capture three video frames and write them as files
- for(i=0; i<3; i++)
- {
- pVideoFrame = cvQueryFrame( pCapture );
- if( !pVideoFrame )
- {
- fprintf(stderr, "failed to get a video frame\n");
- } // Write the captured video frame as an image file
- sprintf(filename, "VideoFrame%d.jpg", i+1);
- if( !cvSaveImage(filename, pVideoFrame) )
- {
- fprintf(stderr, "failed to write image file %s\n", filename);
- } // IMPORTANT: Don't release or modify the image returned
- // from cvQueryFrame() !
- } // Terminate video capture and free capture resources
- cvReleaseCapture( &pCapture ); return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement