-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
38 lines (28 loc) · 1.15 KB
/
main.cpp
File metadata and controls
38 lines (28 loc) · 1.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#include <emscripten.h>
#include <emscripten/bind.h>
#include <emscripten/val.h>
#include <opencv2/objdetect/aruco_board.hpp>
#include <opencv2/opencv.hpp>
extern "C" int main(int argc, char **argv) {
return 0;
}
emscripten::val createChArUco() {
cv::Mat raw;
cv::Mat output;
auto dictionary = cv::aruco::getPredefinedDictionary(cv::aruco::DICT_6X6_250);
cv::aruco::CharucoBoard board = cv::aruco::CharucoBoard(cv::Size(5, 7), 0.04f, 0.02f, dictionary);
board.generateImage(cv::Size(200, 280), raw);
cv::cvtColor(raw, output, cv::COLOR_GRAY2RGBA);
emscripten::val Uint8Array = emscripten::val::global("Uint8Array");
emscripten::memory_view<unsigned char> view = emscripten::typed_memory_view(output.total() * output.elemSize(), output.data);
emscripten::val dataCopy = Uint8Array.new_(view);
emscripten::val result = emscripten::val::object();
result.set("width", output.cols);
result.set("height", output.rows);
result.set("channels", output.channels());
result.set("data", dataCopy);
return result;
}
EMSCRIPTEN_BINDINGS(my_module) {
emscripten::function("createChArUco", &createChArUco);
}