-
Notifications
You must be signed in to change notification settings - Fork 4
/
image_processor.cpp
47 lines (37 loc) · 1.06 KB
/
image_processor.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
#include <opencv2/opencv.hpp>
using namespace std;
class FrameProcessor {
private:
cv::VideoCapture capture;
public:
FrameProcessor(int cameraID) {
capture.open(cameraID);
if (!capture.isOpened()) {
cout << "Failed to open the camera" << endl;
exit(EXIT_FAILURE);
}
}
void capture_and_show(string original_fram_name, string gray_frame_name) {
cv::Mat frame, grayscaleFrame;
while (true) {
capture >> frame;
if (frame.empty()) {
cout << "Captured frame is empty" << endl;
break;
}
cv::imshow(original_fram_name, frame);
cv::cvtColor(frame, grayscaleFrame, cv::COLOR_BGR2GRAY);
cv::imshow(gray_frame_name, grayscaleFrame);
if (cv::waitKey(1) == 'q') {
break;
}
}
capture.release();
cv::destroyAllWindows();
}
};
int main() {
FrameProcessor processor(0);
processor.capture_and_show("Hello", "World");
return 0;
}