-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
76 lines (63 loc) · 2.39 KB
/
main.cpp
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#include <opencv2/opencv.hpp>
#include <opencv2/highgui.hpp>
#include <iostream>
#include <string>
#include <chrono>
#include <ctime>
using namespace std;
using namespace cv;
using namespace chrono;
int main(int argc, char **argv)
{
int camdev_id;
int frame_no = 0;
int frame_end;
double width, height;
double fps;
Mat frame1;
if (argc < 5) {
perror("Too small input arguments\n"
"Insert [resolution_width] [resolution_height] [camdev_id] [frame_no]\n"
"Resolution width : ex, 4096 for 4K video\n"
"Resolution height : ex, 2160 for 4K video\n"
"Camdev_id : camera device id or path. Ex) \"/dev/video0\" or 0\n"
"Frame_no : the number of frame to capture\n");
return 0;
} else if (argc > 5) {
perror("Too many input arguments.\n"
"Insert [resolution_width] [resolution_height] [camdev_id] [frame_no]\n"
"Resolution width : ex, 4096 for 4K video\n"
"Resolution height : ex, 2160 for 4K video\n"
"Camdev_id : camera device id or path. Ex) \"/dev/video0\" or 0\n"
"Frame_no : the number of frame to capture\n");
return 0;
}
width = stod(argv[1]);
height = stod(argv[2]);
camdev_id = stoi(argv[3]);
frame_end = stoi(argv[4]);
VideoCapture cap(camdev_id);
if (!cap.isOpened()) {
perror("Can't open the CAM\n");
return 0;
}
cap.set(CV_CAP_PROP_FRAME_WIDTH, width);
cap.set(CV_CAP_PROP_FRAME_HEIGHT, height);
width = cap.get(CV_CAP_PROP_FRAME_WIDTH);
height = cap.get(CV_CAP_PROP_FRAME_HEIGHT);
cout << "width: " << width << "\n";
cout << "height: " << height << "\n";
auto start = system_clock::now();
while(1) {
if (frame_no > frame_end)
break;
cap >> frame1;
frame_no++;
}
auto end = system_clock::now();
duration<double> elapsed_seconds = end - start;
cout << "elapsed time: " << elapsed_seconds.count() << "s\n";
fps = frame_end / (double)elapsed_seconds.count();
cout << "FPS: " << fps << "\n";
return 0;
}