Advertisement
Guest User

Untitled

a guest
Aug 17th, 2017
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.34 KB | None | 0 0
  1. //
  2. // Example showing how to connect to a webcam and capture
  3. // video frames
  4. // you may need to chanve the openCV library paths to suit your setup.
  5.  
  6. #include </usr/include/opencv/cv.h>
  7. #include </usr/include/opencv/highgui.h>
  8. #include </usr/include/opencv/cxcore.h>
  9. #include "stdio.h"
  10. #include "string.h" int main(int argc, char ** argv)
  11. {
  12. CvCapture * pCapture = 0;
  13. IplImage * pVideoFrame = 0;
  14. int i;
  15. char filename[50]; //returns the number of available cameras in the system
  16. // int ncams = cvcamGetCamerasCount( );
  17. // fprintf(stderr, "Number of cameras: %d\n", ncams); // Initialize video capture
  18. // pCapture = cvCaptureFromCAM( CV_CAP_ANY );
  19. pCapture = cvCaptureFromCAM( -1 );
  20. if( !pCapture )
  21. {
  22. fprintf(stderr, "failed to initialize video capture\n");
  23. return -1;
  24. } // Capture three video frames and write them as files
  25. for(i=0; i<3; i++)
  26. {
  27. pVideoFrame = cvQueryFrame( pCapture );
  28. if( !pVideoFrame )
  29. {
  30. fprintf(stderr, "failed to get a video frame\n");
  31. } // Write the captured video frame as an image file
  32. sprintf(filename, "VideoFrame%d.jpg", i+1);
  33. if( !cvSaveImage(filename, pVideoFrame) )
  34. {
  35. fprintf(stderr, "failed to write image file %s\n", filename);
  36. } // IMPORTANT: Don't release or modify the image returned
  37. // from cvQueryFrame() !
  38. } // Terminate video capture and free capture resources
  39. cvReleaseCapture( &pCapture ); return 0;
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement