Skip to content

Commit 67c707d

Browse files
committed
Improve chapel-webcam demo expresability.
1 parent 0d37d01 commit 67c707d

5 files changed

Lines changed: 45 additions & 12 deletions

File tree

demos/video/chapel-webcam/Makefile

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,12 @@ LIB_GEN_CMD = \
1212
--library \
1313
--dynamic \
1414
--library-dir lib \
15-
--savec lib/savec \
1615
--library-makefile \
17-
--library-cmakelists \
1816
--no-munge-with-ids \
17+
-M ../../../lib \
1918
smol.chpl
19+
# --savec lib/savec \
20+
# --library-cmakelists \
2021
2122

2223
pre-build:

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ CHPL_THIRD_PARTY = /opt/homebrew/Cellar/chapel/2.4.0_1/libexec/third-party
66

77
CHPL_HOME = /opt/homebrew/Cellar/chapel/2.4.0_1/libexec
88

9-
CHPL_CFLAGS = -Ilib -Wno-unused -Wno-uninitialized -Wno-pointer-sign -Wno-incompatible-pointer-types -Wno-tautological-compare -I/opt/homebrew/Cellar/chapel/2.4.0_1/libexec/modules/internal -I$(CHPL_RUNTIME_INCL)/localeModels/flat -I$(CHPL_RUNTIME_INCL)/localeModels -I$(CHPL_RUNTIME_INCL)/comm/none -I$(CHPL_RUNTIME_INCL)/comm -I$(CHPL_RUNTIME_INCL)/tasks/qthreads -I$(CHPL_RUNTIME_INCL)/. -I$(CHPL_RUNTIME_INCL)/./qio -I$(CHPL_RUNTIME_INCL)/./atomics/cstdlib -I$(CHPL_RUNTIME_INCL)/./mem/jemalloc -I$(CHPL_THIRD_PARTY)/utf8-decoder -I$(CHPL_THIRD_PARTY)/qthread/install/darwin-arm64-native-llvm-none-flat-jemalloc-system/include -Wno-error=unused-variable -I$(CHPL_THIRD_PARTY)/re2/install/darwin-arm64-native-llvm-none/include -I. -I/opt/homebrew/Cellar/gmp/6.3.0/include -I/opt/homebrew/Cellar/hwloc/2.12.0/include -I/opt/homebrew/Cellar/jemalloc/5.3.0/include -I/opt/homebrew/include
9+
CHPL_CFLAGS = -Ilib -Wno-unused -Wno-uninitialized -Wno-pointer-sign -Wno-incompatible-pointer-types -Wno-tautological-compare -I/opt/homebrew/Cellar/chapel/2.4.0_1/libexec/modules/internal -I/opt/homebrew/Cellar/chapel/2.4.0_1/libexec/modules/packages -I$(CHPL_RUNTIME_INCL)/localeModels/flat -I$(CHPL_RUNTIME_INCL)/localeModels -I$(CHPL_RUNTIME_INCL)/comm/none -I$(CHPL_RUNTIME_INCL)/comm -I$(CHPL_RUNTIME_INCL)/tasks/qthreads -I$(CHPL_RUNTIME_INCL)/. -I$(CHPL_RUNTIME_INCL)/./qio -I$(CHPL_RUNTIME_INCL)/./atomics/cstdlib -I$(CHPL_RUNTIME_INCL)/./mem/jemalloc -I$(CHPL_THIRD_PARTY)/utf8-decoder -I$(CHPL_THIRD_PARTY)/qthread/install/darwin-arm64-native-llvm-none-flat-jemalloc-system/include -Wno-error=unused-variable -I$(CHPL_THIRD_PARTY)/re2/install/darwin-arm64-native-llvm-none/include -I. -I/opt/homebrew/Cellar/gmp/6.3.0/include -I/opt/homebrew/Cellar/hwloc/2.12.0/include -I/opt/homebrew/Cellar/jemalloc/5.3.0/include -I/opt/homebrew/include
1010

1111
CHPL_LDFLAGS = -Llib -lsmol -L$(CHPL_RUNTIME_LIB)/darwin/llvm/arm64/cpu-native/loc-flat/comm-none/tasks-qthreads/tmr-generic/unwind-none/mem-jemalloc/atomics-cstdlib/hwloc-system/re2-bundled/fs-none/lib_pic-none/san-none -lchpl -L$(CHPL_THIRD_PARTY)/qthread/install/darwin-arm64-native-llvm-none-flat-jemalloc-system/lib -Wl,-rpath,$(CHPL_THIRD_PARTY)/qthread/install/darwin-arm64-native-llvm-none-flat-jemalloc-system/lib -lqthread -L/opt/homebrew/Cellar/hwloc/2.12.0/lib -L$(CHPL_THIRD_PARTY)/re2/install/darwin-arm64-native-llvm-none/lib -lre2 -Wl,-rpath,$(CHPL_THIRD_PARTY)/re2/install/darwin-arm64-native-llvm-none/lib -lm -lpthread -L/opt/homebrew/Cellar/gmp/6.3.0/lib -lgmp -L/opt/homebrew/Cellar/hwloc/2.12.0/lib -Wl,-rpath,/opt/homebrew/Cellar/hwloc/2.12.0/lib -lhwloc -L/opt/homebrew/Cellar/jemalloc/5.3.0/lib -Wl,-rpath,/opt/homebrew/Cellar/jemalloc/5.3.0/lib -ljemalloc -L/opt/homebrew/lib
1212

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#include "stdchpl.h"
22
#include "wctype.h"
33
#include "ctype.h"
4+
#include "ImageHelper/stb_image_helper.h"
45
void chpl__init_smol(int64_t _ln,
56
int32_t _fn);
67
int64_t square(int64_t x);

demos/video/chapel-webcam/main.cpp

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,16 +32,23 @@ cv::Mat new_frame(cv::Mat &frame) {
3232
// cv::Mat new_rgb_frame(height, width, CV_8UC3,new_frame_array.elts);
3333
// cv::cvtColor(new_rgb_frame, new_rgb_frame, cv::COLOR_RGB2BGR);
3434

35+
cv::Mat output_frame(height,width,CV_32FC3,rgb_float_output_frame_array.elts); // frame to write to
36+
output_frame.convertTo(output_frame, CV_8UC3, 255.0f);
37+
cv::cvtColor(output_frame, output_frame, cv::COLOR_RGB2BGR);
3538

36-
cv::Mat rgb_float_output_frame(height,width,CV_32FC3,rgb_float_output_frame_array.elts); // frame to write to
39+
chpl_free_external_array(rgb_float_output_frame_array);
3740

38-
cv::Mat rgb_uchar_output_frame;
39-
rgb_float_output_frame.convertTo(rgb_uchar_output_frame, CV_8UC3, 255.0f);
41+
return output_frame;
42+
43+
// cv::Mat rgb_float_output_frame(height,width,CV_32FC3,rgb_float_output_frame_array.elts); // frame to write to
44+
45+
// cv::Mat rgb_uchar_output_frame;
46+
// rgb_float_output_frame.convertTo(rgb_uchar_output_frame, CV_8UC3, 255.0f);
4047

41-
cv::Mat bgr_uchar_output_frame;
42-
cv::cvtColor(rgb_uchar_output_frame, bgr_uchar_output_frame, cv::COLOR_RGB2BGR);
48+
// cv::Mat bgr_uchar_output_frame;
49+
// cv::cvtColor(rgb_uchar_output_frame, bgr_uchar_output_frame, cv::COLOR_RGB2BGR);
4350

44-
return bgr_uchar_output_frame;
51+
// return bgr_uchar_output_frame;
4552
}
4653

4754
/*

demos/video/chapel-webcam/smol.chpl

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import Utilities as utils;
12

23
export proc square(x: int): int {
34
writeln(x, " * ", x, " = ", x * x);
@@ -14,9 +15,32 @@ export proc sumArray(a: [] int): int {
1415
export proc printArray(a: [] int): void {
1516
writeln(a);
1617
}
17-
export proc getNewFrame(frame: [] real(32),height: int, width: int,channels: int): [] real(32) {
18-
const ret = frame;
19-
return ret;
18+
export proc getNewFrame(ref frame: [] real(32),height: int, width: int,channels: int): [] real(32) {
19+
// const dom = {0..<height,0..<width,0..<channels};
20+
// const rgb: [dom] real(32) = reshape(frame,dom);
21+
// const ret = reshape(rgb,{0..<dom.size});
22+
// return ret;
23+
// return [x in frame] x * 1.2;
24+
25+
// const dom = {0..<height,0..<width,0..<channels};
26+
// const rgb: [dom] real(32) = reshape(frame,dom);
27+
28+
// const m = max reduce frame;
29+
// return [x in frame] m;
30+
31+
const shape = (height,width,channels);
32+
forall (i,color) in zip(0..<frame.size,frame) {
33+
const idx = utils.indexAt(i,(...shape));
34+
const (h,w,c) = idx;
35+
// const color = frame[i];
36+
// if h < width {
37+
// frame[utils.linearIdx(shape,(h,w,c))] = frame[utils.linearIdx(shape,(h,w,c-1))];
38+
// }
39+
if h < width {
40+
frame[utils.linearIdx(shape,(h,w,0))] = 1.0;
41+
}
42+
}
43+
return frame;
2044
}
2145

2246

0 commit comments

Comments
 (0)