Skip to content

Commit 0d37d01

Browse files
committed
Change chapel-webcam demo to use opencv float32 matrix values.
1 parent 939ad69 commit 0d37d01

2 files changed

Lines changed: 47 additions & 4 deletions

File tree

demos/video/chapel-webcam/main.cpp

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,45 @@
66

77

88

9+
cv::Mat new_frame(cv::Mat &frame) {
10+
cv::Mat rgb_uchar_frame;
11+
cv::cvtColor(frame, rgb_uchar_frame, cv::COLOR_BGR2RGB);
12+
13+
cv::Mat rgb_float_frame;
14+
rgb_uchar_frame.convertTo(rgb_float_frame, CV_32FC3, 1.0f/255.0f);
15+
16+
// cv::MatSize size = rgb_frame.size;
17+
// std::cout << "x " << size[0] << " y " << size[1] << " channels " << rgb_frame.dims << std::endl;
18+
int64_t width = rgb_float_frame.cols;
19+
int64_t height = rgb_float_frame.rows;
20+
int64_t channels = rgb_float_frame.channels();
21+
int64_t pixels = rgb_float_frame.total();
22+
int64_t size = pixels * channels;
23+
24+
chpl_external_array
25+
rgb_float_frame_data_ptr = chpl_make_external_array_ptr(rgb_float_frame.data,size);
26+
27+
chpl_external_array
28+
rgb_float_output_frame_array = getNewFrame(&rgb_float_frame_data_ptr, width, height, channels);
29+
30+
chpl_free_external_array(rgb_float_frame_data_ptr);
31+
32+
// cv::Mat new_rgb_frame(height, width, CV_8UC3,new_frame_array.elts);
33+
// cv::cvtColor(new_rgb_frame, new_rgb_frame, cv::COLOR_RGB2BGR);
34+
35+
36+
cv::Mat rgb_float_output_frame(height,width,CV_32FC3,rgb_float_output_frame_array.elts); // frame to write to
37+
38+
cv::Mat rgb_uchar_output_frame;
39+
rgb_float_output_frame.convertTo(rgb_uchar_output_frame, CV_8UC3, 255.0f);
40+
41+
cv::Mat bgr_uchar_output_frame;
42+
cv::cvtColor(rgb_uchar_output_frame, bgr_uchar_output_frame, cv::COLOR_RGB2BGR);
43+
44+
return bgr_uchar_output_frame;
45+
}
46+
47+
/*
948
cv::Mat new_frame(cv::Mat &frame) {
1049
cv::Mat rgb_frame;
1150
cv::cvtColor(frame, rgb_frame, cv::COLOR_BGR2RGB);
@@ -28,7 +67,7 @@ cv::Mat new_frame(cv::Mat &frame) {
2867
2968
return new_rgb_frame;
3069
}
31-
70+
*/
3271

3372
/*
3473
void new_frame(cv::Mat &frame) {

demos/video/chapel-webcam/smol.chpl

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,13 @@ export proc sumArray(a: [] int): int {
1414
export proc printArray(a: [] int): void {
1515
writeln(a);
1616
}
17-
18-
19-
export proc getNewFrame(frame: [] uint(8),height: int, width: int,channels: int): [] uint(8) {
17+
export proc getNewFrame(frame: [] real(32),height: int, width: int,channels: int): [] real(32) {
2018
const ret = frame;
2119
return ret;
2220
}
21+
22+
23+
// export proc getNewFrame(frame: [] uint(8),height: int, width: int,channels: int): [] uint(8) {
24+
// const ret = frame;
25+
// return ret;
26+
// }

0 commit comments

Comments
 (0)