Skip to content

Commit b603c16

Browse files
committed
Complete chapel-webcam demo with opencv.
1 parent 8f9f844 commit b603c16

2 files changed

Lines changed: 41 additions & 41 deletions

File tree

demos/video/chapel-webcam/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ OPENCV_LDFLAGS = `pkg-config --cflags --libs opencv4`
3737

3838
main: main.cpp smol_wrapper.h lib/libsmol.so
3939
@echo $(OPENCV_CFLAGS)
40-
$(CHPL_COMPILER) $(CHPL_CFLAGS) $(OPENCV_CFLAGS) -std=c++20 -fPIC main.cpp -o main $(CHPL_LDFLAGS) $(OPENCV_LDFLAGS)
40+
$(CHPL_LINKER) $(CHPL_CFLAGS) $(OPENCV_CFLAGS) -std=c++20 -fPIC main.cpp -o main $(CHPL_LDFLAGS) $(OPENCV_LDFLAGS)
4141

4242
clean:
4343
rm -f maincpp maincpp.o main.o main

demos/video/chapel-webcam/main.cpp

Lines changed: 40 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,46 @@
11
#include "smol_wrapper.h"
22

33

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; }
4444

4545
int main(int argc, char* argv[]) {
4646
chpl_library_init(argc, argv);

0 commit comments

Comments
 (0)