Video Capture

Capture Video data from camera and save

Press ESC to exit program.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#include <iostream>
#include <string>
#include <opencv2/opencv.hpp>
#include <video.hpp>

using namespace std;
using namespace cv;

int main(int argc, char *argv[])
{

if (argc < 2) {
cout << "[Usage]" << endl;
cout << "\t ./VideoCapture save_filename" << endl;
return -1;
}
VideoCapture vc;
vc.open(0);
if (!vc.isOpened()) {
cout << "[ERROR] Camera can't open" << endl;
return -2;
}
VideoWriter vw;
vw.open( argv[1], // Saved filename
(int)vc.get( CV_CAP_PROP_FOURCC ), // Windows:CV_FOURCC_PROMPT(-1) can select parameters in a Dialog
(double)vc.get( CV_CAP_PROP_FPS ), // FPS
cv::Size( (int)vc.get( CV_CAP_PROP_FRAME_WIDTH ), (int)vc.get( CV_CAP_PROP_FRAME_HEIGHT ) ), // Resolution
true ); // Color or not);
if (!vw.isOpened()) {
cout << "[ERROR] Saved file can't open" << endl;
return -3;
}
//Capture
Mat frame;
for (long long framecnt = 0; vc.read(frame) && waitKey(33) != 27; framecnt++) {
vw << frame;
}
vc.release();
vw.release();
return 0;
}

Contents
  1. 1. Capture Video data from camera and save