This repo contains an example that compile OpenCV C++ code into wasm, and runs the generated wasm code in React app. It includes:
- How to set up build to generate wasm from custom opencv C++ code
- How to load wasm into react and call the custom functions.
To compile C++ code into wasm and run the React app, we need:
- emscripten, install by following instructions in https://emscripten.org/docs/getting_started/downloads.html
- node.js
git submodule update --init --recursive
to pull opencv repo- Find out your emscripten path
$EMSCRIPTEN_PATH
- Build opencv wasm by running
EMSCRIPTEN=$EMSCRIPTEN_PATH python3 opencv/platforms/js/build_js.py opencv/build_wasm --build_wasm
For linux machine, the common EMSCRIPTEN_PATH is export EMSCRIPTEN_PATH=~/emsdk/upstream/emscripten
Modify and add the path to workspace.json.
{
"C_Cpp.default.includePath": [
"${workspaceFolder}/opencv/include",
"/home/randxie/emsdk/upstream/emscripten/system/include",
],
}
make build-wasm
It will generate vision_utils.js
that gets copied to app/src
.
cd app & npm install
make run-app