Hi there ๐
taylorjg / emscripten-opencv Goto Github PK
View Code? Open in Web Editor NEWWeb app calling into C++ WebAssembly code that uses OpenCV
Web app calling into C++ WebAssembly code that uses OpenCV
Hi there ๐
Thank you for providing your repository. This is really useful.
I am trying to modify the code to use the readNet
from the cv dnn package. However, I am unable to compile my project and I getting an error related to protobuf. Can you help me?
Error:
> [email protected] start:dev
> npm run build:wasm && webpack serve
> [email protected] build:wasm
> docker run --rm -t -w /src -v "$PWD"/../opencv:/src/opencv -v "$PWD":/src/emscripten-opencv emscripten/emsdk sh emscripten-opencv/build-wasm.sh
WARNING: The requested image's platform (linux/amd64) does not match the detected host platform (linux/arm64/v8) and no specific platform was requested
SCRIPT_DIR=/src/emscripten-opencv
BUILD_DIR=/src/emscripten-opencv/build
configure: cmake -D BUILD_PROTOBUF=OFF /src/emscripten-opencv -DCMAKE_TOOLCHAIN_FILE=/emsdk/upstream/emscripten/cmake/Modules/Platform/Emscripten.cmake -DCMAKE_CROSSCOMPILING_EMULATOR=/emsdk/node/14.18.2_64bit/bin/node;--experimental-wasm-bulk-memory;--experimental-wasm-threads
-- Configuring done
-- Generating done
-- Build files have been written to: /src/emscripten-opencv/build
make: make clean
make: make
[ 50%] Building CXX object CMakeFiles/hello.dir/src/hello.cpp.o
[100%] Linking CXX executable hello.js
cache:INFO: generating system asset: symbol_lists/6e44eebc7b3ea6c9a9b35e4e26568ccea824d391.txt... (this will be cached in "/emsdk/upstream/emscripten/cache/symbol_lists/6e44eebc7b3ea6c9a9b35e4e26568ccea824d391.txt" for subsequent builds)
cache:INFO: - ok
ports:INFO: retrieving port: zlib from https://github.com/madler/zlib/archive/refs/tags/v1.2.13.tar.gz
ports:INFO: unpacking port: zlib
cache:INFO: generating port: sysroot/lib/wasm32-emscripten/libz.a... (this will be cached in "/emsdk/upstream/emscripten/cache/sysroot/lib/wasm32-emscripten/libz.a" for subsequent builds)
system_libs:INFO: compiled 15 inputs
cache:INFO: - ok
wasm-ld: error: ../../opencv/build_wasm/lib/libopencv_dnn.a(opencv-caffe.pb.cc.o): undefined symbol: google::protobuf::internal::VerifyVersion(int, int, char const*)
wasm-ld: error: ../../opencv/build_wasm/lib/libopencv_dnn.a(opencv-caffe.pb.cc.o): undefined symbol: google::protobuf::internal::InitProtobufDefaults()
wasm-ld: error: ../../opencv/build_wasm/lib/libopencv_dnn.a(opencv-caffe.pb.cc.o): undefined symbol: google::protobuf::internal::OnShutdownDestroyMessage(void const*)
wasm-ld: error: ../../opencv/build_wasm/lib/libopencv_dnn.a(opencv-caffe.pb.cc.o): undefined symbol: google::protobuf::internal::VerifyVersion(int, int, char const*)
wasm-ld: error: ../../opencv/build_wasm/lib/libopencv_dnn.a(opencv-caffe.pb.cc.o): undefined symbol: google::protobuf::internal::InitProtobufDefaults()
wasm-ld: error: ../../opencv/build_wasm/lib/libopencv_dnn.a(opencv-caffe.pb.cc.o): undefined symbol: vtable for google::protobuf::internal::FunctionClosure0
wasm-ld: error: ../../opencv/build_wasm/lib/libopencv_dnn.a(opencv-caffe.pb.cc.o): undefined symbol: google::protobuf::GoogleOnceInitImpl(long*, google::protobuf::Closure*)
wasm-ld: error: ../../opencv/build_wasm/lib/libopencv_dnn.a(opencv-caffe.pb.cc.o): undefined symbol: google::protobuf::internal::FunctionClosure0::~FunctionClosure0()
wasm-ld: error: ../../opencv/build_wasm/lib/libopencv_dnn.a(opencv-caffe.pb.cc.o): undefined symbol: google::protobuf::internal::fixed_address_empty_string
wasm-ld: error: ../../opencv/build_wasm/lib/libopencv_dnn.a(opencv-caffe.pb.cc.o): undefined symbol: google::protobuf::internal::OnShutdownDestroyMessage(void const*)
wasm-ld: error: ../../opencv/build_wasm/lib/libopencv_dnn.a(opencv-caffe.pb.cc.o): undefined symbol: google::protobuf::internal::VerifyVersion(int, int, char const*)
wasm-ld: error: ../../opencv/build_wasm/lib/libopencv_dnn.a(opencv-caffe.pb.cc.o): undefined symbol: google::protobuf::internal::InitProtobufDefaults()
wasm-ld: error: ../../opencv/build_wasm/lib/libopencv_dnn.a(opencv-caffe.pb.cc.o): undefined symbol: vtable for google::protobuf::internal::FunctionClosure0
wasm-ld: error: ../../opencv/build_wasm/lib/libopencv_dnn.a(opencv-caffe.pb.cc.o): undefined symbol: google::protobuf::GoogleOnceInitImpl(long*, google::protobuf::Closure*)
wasm-ld: error: ../../opencv/build_wasm/lib/libopencv_dnn.a(opencv-caffe.pb.cc.o): undefined symbol: google::protobuf::internal::FunctionClosure0::~FunctionClosure0()
wasm-ld: error: ../../opencv/build_wasm/lib/libopencv_dnn.a(opencv-caffe.pb.cc.o): undefined symbol: google::protobuf::internal::OnShutdownDestroyMessage(void const*)
wasm-ld: error: ../../opencv/build_wasm/lib/libopencv_dnn.a(opencv-caffe.pb.cc.o): undefined symbol: google::protobuf::internal::VerifyVersion(int, int, char const*)
wasm-ld: error: ../../opencv/build_wasm/lib/libopencv_dnn.a(opencv-caffe.pb.cc.o): undefined symbol: google::protobuf::internal::InitProtobufDefaults()
wasm-ld: error: ../../opencv/build_wasm/lib/libopencv_dnn.a(opencv-caffe.pb.cc.o): undefined symbol: google::protobuf::internal::OnShutdownDestroyMessage(void const*)
wasm-ld: error: ../../opencv/build_wasm/lib/libopencv_dnn.a(opencv-caffe.pb.cc.o): undefined symbol: google::protobuf::internal::VerifyVersion(int, int, char const*)
wasm-ld: error: too many errors emitted, stopping now (use -error-limit=0 to see all errors)
em++: error: '/emsdk/upstream/bin/wasm-ld -o hello.wasm CMakeFiles/hello.dir/src/hello.cpp.o ../../opencv/build_wasm/lib/libopencv_calib3d.a ../../opencv/build_wasm/lib/libopencv_core.a ../../opencv/build_wasm/lib/libopencv_dnn.a ../../opencv/build_wasm/lib/libopencv_features2d.a ../../opencv/build_wasm/lib/libopencv_flann.a ../../opencv/build_wasm/lib/libopencv_imgproc.a ../../opencv/build_wasm/lib/libopencv_objdetect.a ../../opencv/build_wasm/lib/libopencv_photo.a ../../opencv/build_wasm/lib/libopencv_video.a -L/emsdk/upstream/emscripten/cache/sysroot/lib/wasm32-emscripten /emsdk/upstream/emscripten/cache/sysroot/lib/wasm32-emscripten/libz.a --whole-archive -lembind-rtti --no-whole-archive -lGL -lal -lhtml5 -lstubs -lnoexit -lc -ldlmalloc -lcompiler_rt -lc++-noexcept -lc++abi-noexcept -lsockets -mllvm -combiner-global-alias-analysis=false -mllvm -enable-emscripten-sjlj -mllvm -disable-lsr --allow-undefined-file=/tmp/tmppcsoe5xy.undefined --strip-debug --export-if-defined=free --export-if-defined=__start_em_asm --export-if-defined=__stop_em_asm --export-if-defined=__start_em_lib_deps --export-if-defined=__stop_em_lib_deps --export-if-defined=__start_em_js --export-if-defined=__stop_em_js --export=stackSave --export=stackRestore --export=stackAlloc --export=__errno_location --export=__get_temp_ret --export=__set_temp_ret --export=malloc --export=free --export=__wasm_call_ctors --export=__cxa_is_pointer_type --export-table -z stack-size=65536 --initial-memory=16777216 --no-entry --max-memory=16777216 --global-base=1024' failed (returned 1)
make[2]: *** [CMakeFiles/hello.dir/build.make:109: hello.js] Error 1
make[1]: *** [CMakeFiles/Makefile2:83: CMakeFiles/hello.dir/all] Error 2
make: *** [Makefile:91: all] Error 2
emmake: error: 'make' failed (returned 2)
CMakeLists.txt
set(OPENCV_DIR "../opencv")
cmake_minimum_required(VERSION 3.1)
project(HelloCV)
# Use C++ 11 by default
set(CMAKE_CXX_STANDARD 11)
# Set Release as default build type
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Release)
endif(NOT CMAKE_BUILD_TYPE)
# Needed for opencv2/opencv.hpp
include_directories("${OPENCV_DIR}/include")
# Needed by opencv.hpp for opencv2/opencv_modules.hpp
include_directories("${OPENCV_DIR}/build_wasm")
# Needed by opencv_modules.hpp for every module
file(GLOB opencv_include_modules "${OPENCV_DIR}/modules/*/include")
include_directories(${opencv_include_modules})
# Our hello world executable
add_executable(hello src/hello.cpp)
# Link to opencv.js precompiled libraries
file(GLOB opencv_libs "${OPENCV_DIR}/build_wasm/lib/*.a")
target_link_libraries(hello ${opencv_libs} )
# There is an issue regarding the order in which libraries
link_directories(/opt/homebrew/Cellar/protobuf/21.12/)
set_target_properties(hello PROPERTIES LINK_FLAGS "-s EXPORTED_RUNTIME_METHODS=cwrap -s USE_ZLIB=1 -s EXPORTED_FUNCTIONS=_free -s MODULARIZE=1 -s EXPORT_NAME=createHelloModule --bind")
Hey @jonathan,
This repo is exactly what I need. Without it, It would be really hard to do my project.
I get the image from JS and do some processing on it and return it to JS as you did in the project. Everything works fine.
But since the JS side does not need to show the image and wants to just send it, I thought that it would be more efficient if I can encode the image and return the image to JS as a string so JS won't need to do so.
I tried to encode Mat
using imencode
In my C++ code, which received the following error:
error: undefined symbol: _ZN2cv8imencodeERKNSt3__212basic_stringIcNS0_11char_traitsIcEENS0_9allocatorIcEEEERKNS_11_InputArrayERNS0_6vectorIhNS4_IhEEEERKNSC_IiNS4_IiEEEE (referenced by top-level compiled C/C++ code)
I know that it is because the project is not linked with imgcodec
. So I edit the opencv/platforms/js/build_js.py
file and add -DBUILD_opencv_imgcodecs=ON
to it and recompile OpenCV. But still, It does not build imgcodec
library.
Do you have any idea how I can build OpenCV with imgcodec
?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.