|
1 | 1 | #include "smol_wrapper.h" |
2 | 2 |
|
3 | 3 |
|
4 | | -// #include <opencv2/opencv.hpp> |
5 | | -// #include <iostream> |
6 | | - |
7 | | - |
8 | | -// int mirror() { |
9 | | -// cv::VideoCapture cap(0); |
10 | | -// if (!cap.isOpened()) { |
11 | | -// std::cerr << "Error: Cannot open the webcam.\n"; |
12 | | -// return -1; |
13 | | -// } |
14 | | - |
15 | | -// cv::Mat frame; |
16 | | -// const std::string windowName = "Webcam Feed"; |
17 | | -// cv::namedWindow(windowName, cv::WINDOW_AUTOSIZE); |
18 | | - |
19 | | -// while (true) { |
20 | | -// // Capture a new frame from webcam |
21 | | -// cap >> frame; |
22 | | -// if (frame.empty()) { |
23 | | -// std::cerr << "Error: Empty frame captured.\n"; |
24 | | -// break; |
25 | | -// } |
26 | | - |
27 | | -// // Display the captured frame |
28 | | -// cv::imshow(windowName, frame); |
29 | | - |
30 | | -// // Wait for 30ms or until 'q' key is pressed |
31 | | -// char key = static_cast<char>(cv::waitKey(30)); |
32 | | -// if (key == 'q' || key == 27) { // 'q' or ESC to quit |
33 | | -// break; |
34 | | -// } |
35 | | -// } |
36 | | - |
37 | | -// // Release the camera and destroy all windows |
38 | | -// cap.release(); |
39 | | -// cv::destroyAllWindows(); |
40 | | -// return 0; |
41 | | -// } |
42 | | - |
43 | | -int mirror() { return 0; } |
| 4 | +#include <opencv2/opencv.hpp> |
| 5 | +#include <iostream> |
| 6 | + |
| 7 | + |
| 8 | +int mirror() { |
| 9 | + cv::VideoCapture cap(0); |
| 10 | + if (!cap.isOpened()) { |
| 11 | + std::cerr << "Error: Cannot open the webcam.\n"; |
| 12 | + return -1; |
| 13 | + } |
| 14 | + |
| 15 | + cv::Mat frame; |
| 16 | + const std::string windowName = "Webcam Feed"; |
| 17 | + cv::namedWindow(windowName, cv::WINDOW_AUTOSIZE); |
| 18 | + |
| 19 | + while (true) { |
| 20 | + // Capture a new frame from webcam |
| 21 | + cap >> frame; |
| 22 | + if (frame.empty()) { |
| 23 | + std::cerr << "Error: Empty frame captured.\n"; |
| 24 | + break; |
| 25 | + } |
| 26 | + |
| 27 | + // Display the captured frame |
| 28 | + cv::imshow(windowName, frame); |
| 29 | + |
| 30 | + // Wait for 30ms or until 'q' key is pressed |
| 31 | + char key = static_cast<char>(cv::waitKey(30)); |
| 32 | + if (key == 'q' || key == 27) { // 'q' or ESC to quit |
| 33 | + break; |
| 34 | + } |
| 35 | + } |
| 36 | + |
| 37 | + // Release the camera and destroy all windows |
| 38 | + cap.release(); |
| 39 | + cv::destroyAllWindows(); |
| 40 | + return 0; |
| 41 | +} |
| 42 | + |
| 43 | +// int mirror() { return 0; } |
44 | 44 |
|
45 | 45 | int main(int argc, char* argv[]) { |
46 | 46 | chpl_library_init(argc, argv); |
|
0 commit comments