|
| 1 | +#include "mirror.h" |
| 2 | + |
1 | 3 | #include <opencv2/opencv.hpp> |
2 | 4 | #include <iostream> |
3 | | -#include "mirror.h" |
4 | 5 |
|
5 | | -extern "C" void run_mirror() { |
6 | | - cv::VideoCapture cap(0); // Open the default camera (0) |
| 6 | +// extern "C" void run_mirror() asm ("run_mirror"); |
| 7 | +extern "C" int run_mirror(void) { |
| 8 | + // cv::VideoCapture cap(0); // Open the default camera (0) |
| 9 | + // if (!cap.isOpened()) { |
| 10 | + // std::cerr << "Error: Could not open camera." << std::endl; |
| 11 | + // } |
| 12 | + |
| 13 | + // cv::Mat frame; |
| 14 | + // while (true) { |
| 15 | + // cap >> frame; // Capture a new frame |
| 16 | + // if (frame.empty()) { |
| 17 | + // std::cerr << "Error: Could not capture frame." << std::endl; |
| 18 | + // break; |
| 19 | + // } |
| 20 | + |
| 21 | + // cv::imshow("Webcam", frame); // Display the captured frame |
| 22 | + // if (cv::waitKey(30) >= 0) break; // Exit on any key press |
| 23 | + // } |
| 24 | + |
| 25 | + // cap.release(); // Release the camera |
| 26 | + // cv::destroyAllWindows(); // Close all OpenCV windows |
| 27 | + |
| 28 | + cv::VideoCapture cap(0); |
7 | 29 | if (!cap.isOpened()) { |
8 | | - std::cerr << "Error: Could not open camera." << std::endl; |
| 30 | + std::cerr << "Error: Could not open webcam" << std::endl; |
| 31 | + return -1; |
9 | 32 | } |
10 | 33 |
|
11 | 34 | cv::Mat frame; |
| 35 | + const std::string window_name = "Webcam"; |
| 36 | + |
| 37 | + // Create a window to display the video |
| 38 | + cv::namedWindow(window_name, cv::WINDOW_AUTOSIZE); |
| 39 | + |
12 | 40 | while (true) { |
13 | | - cap >> frame; // Capture a new frame |
| 41 | + // Capture a new frame from the camera |
| 42 | + cap >> frame; |
14 | 43 | if (frame.empty()) { |
15 | | - std::cerr << "Error: Could not capture frame." << std::endl; |
| 44 | + std::cerr << "Error: Blank frame grabbed" << std::endl; |
16 | 45 | break; |
17 | 46 | } |
18 | 47 |
|
19 | | - cv::imshow("Webcam", frame); // Display the captured frame |
20 | | - if (cv::waitKey(30) >= 0) break; // Exit on any key press |
| 48 | + // Show the frame in the window |
| 49 | + cv::imshow(window_name, frame); |
| 50 | + |
| 51 | + // Wait for 30ms. Exit if any key is pressed. |
| 52 | + if (cv::waitKey(30) >= 0) break; |
21 | 53 | } |
22 | 54 |
|
23 | | - cap.release(); // Release the camera |
24 | | - cv::destroyAllWindows(); // Close all OpenCV windows |
| 55 | + // Release the camera and destroy the window |
| 56 | + cap.release(); |
| 57 | + cv::destroyAllWindows(); |
| 58 | + |
| 59 | + return 0; |
| 60 | + |
25 | 61 | } |
26 | 62 |
|
0 commit comments