Skip to content

Commit e79a86a

Browse files
committed
Chapel from C++ mirror working.
1 parent b603c16 commit e79a86a

3 files changed

Lines changed: 63 additions & 3 deletions

File tree

demos/video/chapel-webcam/lib/smol.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,7 @@ void chpl__init_smol(int64_t _ln,
66
int64_t square(int64_t x);
77
int64_t sumArray(chpl_external_array * a);
88
void printArray(chpl_external_array * a);
9+
chpl_external_array getNewFrame(chpl_external_array * frame,
10+
int64_t height,
11+
int64_t width,
12+
int64_t channels);

demos/video/chapel-webcam/main.cpp

Lines changed: 54 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,58 @@
55
#include <iostream>
66

77

8+
9+
cv::Mat new_frame(cv::Mat &frame) {
10+
cv::Mat rgb_frame;
11+
cv::cvtColor(frame, rgb_frame, cv::COLOR_BGR2RGB);
12+
std::cout << "Frame size: " << rgb_frame.size() << std::endl;
13+
14+
// cv::MatSize size = rgb_frame.size;
15+
// std::cout << "x " << size[0] << " y " << size[1] << " channels " << rgb_frame.dims << std::endl;
16+
int64_t width = rgb_frame.cols;
17+
int64_t height = rgb_frame.rows;
18+
int64_t channels = rgb_frame.channels();
19+
int64_t pixels = rgb_frame.total();
20+
int64_t size = pixels * channels;
21+
22+
chpl_external_array frame_data_ptr = chpl_make_external_array_ptr(rgb_frame.data, size);
23+
chpl_external_array new_frame_array = getNewFrame(&frame_data_ptr, width, height, channels);
24+
chpl_free_external_array(frame_data_ptr);
25+
26+
cv::Mat new_rgb_frame(height, width, CV_8UC3,new_frame_array.elts);
27+
cv::cvtColor(new_rgb_frame, new_rgb_frame, cv::COLOR_RGB2BGR);
28+
29+
// chpl_free_external_array(new_frame_array);
30+
31+
return new_rgb_frame;
32+
33+
// std::cout << "Width: " << width << ", Height: " << height << ", Channels: " << channels << ", Size: " << size << std::endl;
34+
35+
36+
37+
// chpl_external_array frame_data_ptr = chpl_make_external_array_ptr(rgb_frame.data, );
38+
}
39+
40+
41+
/*
42+
void new_frame(cv::Mat &frame) {
43+
cv::Mat rgb_frame;
44+
cv::cvtColor(frame, rgb_frame, cv::COLOR_BGR2RGB);
45+
std::cout << "Frame size: " << rgb_frame.size() << std::endl;
46+
47+
// cv::MatSize size = rgb_frame.size;
48+
// std::cout << "x " << size[0] << " y " << size[1] << " channels " << rgb_frame.dims << std::endl;
49+
int64_t width = rgb_frame.cols;
50+
int64_t height = rgb_frame.rows;
51+
int64_t channels = rgb_frame.channels();
52+
int64_t size = rgb_frame.total() * channels;
53+
54+
std::cout << "Width: " << width << ", Height: " << height << ", Channels: " << channels << ", Size: " << size << std::endl;
55+
56+
// chpl_external_array frame_data_ptr = chpl_make_external_array_ptr(rgb_frame.data, );
57+
}*/
58+
59+
860
int mirror() {
961
cv::VideoCapture cap(0);
1062
if (!cap.isOpened()) {
@@ -23,9 +75,9 @@ int mirror() {
2375
std::cerr << "Error: Empty frame captured.\n";
2476
break;
2577
}
26-
78+
cv::Mat next_frame = new_frame(frame);
2779
// Display the captured frame
28-
cv::imshow(windowName, frame);
80+
cv::imshow(windowName, next_frame);
2981

3082
// Wait for 30ms or until 'q' key is pressed
3183
char key = static_cast<char>(cv::waitKey(30));
@@ -40,7 +92,6 @@ int mirror() {
4092
return 0;
4193
}
4294

43-
// int mirror() { return 0; }
4495

4596
int main(int argc, char* argv[]) {
4697
chpl_library_init(argc, argv);

demos/video/chapel-webcam/smol.chpl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,8 @@ export proc printArray(a: [] int): void {
1515
writeln(a);
1616
}
1717

18+
19+
export proc getNewFrame(frame: [] uint(8),height: int, width: int,channels: int): [] uint(8) {
20+
const ret = frame;
21+
return ret;
22+
}

0 commit comments

Comments
 (0)