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+
860int 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
4596int main (int argc, char * argv[]) {
4697 chpl_library_init (argc, argv);
0 commit comments