-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathshowCamera.cpp
More file actions
55 lines (42 loc) · 1.37 KB
/
showCamera.cpp
File metadata and controls
55 lines (42 loc) · 1.37 KB
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
#include <opencv2/core.hpp>
#include <opencv2/videoio.hpp>
#include <opencv2/highgui.hpp>
#include <nlohmann/json.hpp>
#include <iostream>
#include <fstream>
using json = nlohmann::json;
int main(int argc, char *argv[])
{
std::ifstream configFile(CONFIG_JSON_FILE_PATH, std::ifstream::in);
json config = json::parse(configFile);
cv::Mat frame;
cv::VideoCapture cap;
int apiPreference = cv::CAP_ANY;
#ifdef LINUX_OS
apiPreference = cv::CAP_V4L;
#endif
cap.open(config["camera_index"].get<int>(), apiPreference);
cap.set(cv::CAP_PROP_FRAME_WIDTH, config["camera_width"].get<int>());
cap.set(cv::CAP_PROP_FRAME_HEIGHT, config["camera_height"].get<int>());
int fourcc = cv::VideoWriter::fourcc('B', 'G', 'R', '3');
cap.set(cv::CAP_PROP_FOURCC, fourcc);
if (!cap.isOpened()) {
std::cerr << "Error: Unable to open camera!" << std::endl;
return -1;
}
int imageSeq = 0;
for (;;) {
cap.read(frame);
if (frame.empty()) {
std::cerr << "Error: Blank frame grabbed!" << std::endl;
break;
}
cv::imshow("Stereo Image", frame);
std::cout << "Image " << imageSeq++ << " received with size " << frame.cols << " x " << frame.rows << "." << std::endl;
// esc to quit
if (cv::waitKey(1) == 27) {
break;
}
}
return 0;
}