Advertisement
Guest User

Untitled

a guest
Nov 18th, 2019
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.38 KB | None | 0 0
  1. #include "opencv2/opencv.hpp"
  2. #include <iostream>
  3.  
  4. using namespace std;
  5. using namespace cv;
  6.  
  7. int main(){
  8.  
  9. // Create a VideoCapture object and use camera to capture the video
  10. VideoCapture cap(0);
  11.  
  12. // Check if camera opened successfully
  13. if(!cap.isOpened())
  14. {
  15. cout << "Error opening video stream" << endl;
  16. return -1;
  17. }
  18.  
  19. // Default resolution of the frame is obtained.The default resolution is system dependent.
  20. int frame_width = cap.get(CV_CAP_PROP_FRAME_WIDTH);
  21. int frame_height = cap.get(CV_CAP_PROP_FRAME_HEIGHT);
  22.  
  23. // Define the codec and create VideoWriter object.The output is stored in 'outcpp.avi' file.
  24. VideoWriter video("outcpp.avi",CV_FOURCC('M','J','P','G'),10, Size(frame_width,frame_height));
  25. while(1)
  26. {
  27. Mat frame;
  28.  
  29. // Capture frame-by-frame
  30. cap >> frame;
  31.  
  32. // If the frame is empty, break immediately
  33. if (frame.empty())
  34. break;
  35.  
  36. // Write the frame into the file 'outcpp.avi'
  37. video.write(frame);
  38.  
  39. // Display the resulting frame
  40. imshow( "Frame", frame );
  41.  
  42. // Press ESC on keyboard to exit
  43. char c = (char)waitKey(1);
  44. if( c == 27 )
  45. break;
  46. }
  47.  
  48. // When everything done, release the video capture and write object
  49. cap.release();
  50. video.release();
  51.  
  52. // Closes all the windows
  53. destroyAllWindows();
  54. return 0;
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement