Skip to content

Commit aed5d9d

Browse files
committed
Add mirror opencv chapel working.
1 parent c4a4cb1 commit aed5d9d

8 files changed

Lines changed: 74 additions & 19 deletions

File tree

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1-
/usr/bin/clang++ -std=c++20 -c -fPIC mirror.cpp -o mirror.o -I ../../../libtorch/include -I ../../../libtorch/include/torch/csrc/api/include $(pkg-config --cflags --libs opencv4) -L ../../../libtorch/lib -ltorch -ltorch_cpu -lc10 -ltorch_global_deps
1+
# /usr/bin/clang++ -std=c++20 -c -fPIC mirror.cpp -o mirror.o -I ../../../libtorch/include -I ../../../libtorch/include/torch/csrc/api/include $(pkg-config --cflags --libs opencv4) -L ../../../libtorch/lib -ltorch -ltorch_cpu -lc10 -ltorch_global_deps
2+
# /usr/bin/clang++ -shared -o libmirror.dylib mirror.o -I ../../../libtorch/include -I ../../../libtorch/include/torch/csrc/api/include $(pkg-config --cflags --libs opencv4) -L ../../../libtorch/lib -ltorch -ltorch_cpu -lc10 -ltorch_global_deps
23

3-
/usr/bin/clang++ -shared -o libmirror.dylib mirror.o -I ../../../libtorch/include -I ../../../libtorch/include/torch/csrc/api/include $(pkg-config --cflags --libs opencv4) -L ../../../libtorch/lib -ltorch -ltorch_cpu -lc10 -ltorch_global_deps
4+
# /usr/bin/clang++ -std=c++20 -c -fPIC mirror.cpp -o mirror.o $(pkg-config --cflags --libs opencv4)
5+
6+
g++ -std=c++20 -c -fPIC mirror.cpp -o mirror.o $(pkg-config --cflags opencv4)
7+
chpl mirror.h mirror.o mirror.chpl --fast --print-commands --ldflags $(pkg-config --cflags --libs opencv4) -lstdc++
-40.6 KB
Binary file not shown.
Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,22 @@
11

22
use CTypes;
33

4-
require "mirror.h", "-lmirror";
4+
// require "mirror.h", "-lmirror";
5+
// require "mirror.h libmirror.a";
6+
// require "mirror.h";
57

6-
extern proc run_mirror(): void;
8+
// require "mirror.h", "mirror.o";
9+
10+
// g++ -std=c++17 -O2 -fPIC -c mirror.cpp -o mirror.o $(pkg-config --cflags --libs opencv4)
11+
// chpl mirror.h mirror.o mirror.chpl --print-commands --ldflags $(pkg-config --cflags --libs opencv4)
12+
13+
extern proc run_mirror(): int;
714

815

916
proc main(args: [] string) {
1017
writeln("Hello, world!");
1118

12-
run_mirror();
19+
var x = run_mirror();
20+
writeln("x: ", x);
21+
writeln("Done!");
1322
}
Lines changed: 46 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,62 @@
1+
#include "mirror.h"
2+
13
#include <opencv2/opencv.hpp>
24
#include <iostream>
3-
#include "mirror.h"
45

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);
729
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;
932
}
1033

1134
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+
1240
while (true) {
13-
cap >> frame; // Capture a new frame
41+
// Capture a new frame from the camera
42+
cap >> frame;
1443
if (frame.empty()) {
15-
std::cerr << "Error: Could not capture frame." << std::endl;
44+
std::cerr << "Error: Blank frame grabbed" << std::endl;
1645
break;
1746
}
1847

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;
2153
}
2254

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+
2561
}
2662

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11

2-
#ifndef MIRROR_H
3-
#define MIRROR_H
2+
// #ifndef MIRROR_H
3+
// #define MIRROR_H
44

55
#ifdef __cplusplus
66
extern "C" {
77
#endif
88

9-
void run_mirror();
9+
int run_mirror(void);
1010

1111
#ifdef __cplusplus
1212
}
1313
#endif
1414

15-
#endif // MIRROR_H
15+
// #endif // MIRROR_H
160 Bytes
Binary file not shown.

demos/video/style-transfer/mprog.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#include "mirror.h"
2+
3+
int main() {
4+
run_mirror();
5+
return 1;
6+
}

demos/video/style-transfer/mprog.o

576 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)