Skip to content

Building OpenCV.js with projectPoints + solvePnP #15299

@kavikode

Description

@kavikode

Porting to JavaScript: "Cannot register public name 'projectPoints' twice"

I did the following:

  1. git clone https://github.com/opencv/opencv.git

  2. git clone https://github.com/opencv/opencv_contrib.git

  3. I added the following in def get_build_flags(self) of opencv/platforms/js/build_js.py:
    flags += "-s USE_PTHREADS=0 "

  4. I enabled the build flag in def get_cmake_cmd(self): of opencv/platforms/js/build_js.py:-DBUILD_opencv_calib3d set to ON

  5. I added the following def get_cmake_cmd(self): of opencv/platforms/js/build_js.py:-DOPENCV_EXTRA_MODULES_PATH=~/opencv_contrib/modules

  6. I appended js inside ocv_define_module at the end of WRAP list of opencv/modules/calib3d/CMakeLists.txt. In opencv/modules/features2d/CMakeLists.txt and opencv_contrib/modules/aruco/CMakeLists.txt also I added "js" parameter in ocv_define_module.

  7. I added solvePnPand 'projectPoints' in the calib3d module in the opencv/modules/js/src/embindgen.py

calib3d = {'': ['findHomography','calibrateCameraExtended', 'drawFrameAxes',
'getDefaultNewCameraMatrix', 'initUndistortRectifyMap', 'solvePnP','projectPoints']}

  1. I added the calib3d module to the makeWhiteList in the opencv/modules/js/src/embindgen.py

white_list = makeWhiteList([core, imgproc, objdetect, video, dnn, features2d, photo, aruco, calib3d])

  1. I added "using namespace aruco;" in the opencv/modules/js/src/core_bindings.cpp

  2. I built OpenCV.js using the following command:
    sudo python ./platforms/js/build_js.py build_js --emscripten_dir=${EMSCRIPTEN} --clean_build_dir --build_test

Before adding these wrappers, it compiled perfectly without errors. Now in my tests.html I have the following message:
Downloading...
tests.html:61 Running...
tests.html:61 Exception thrown, see JavaScript console
opencv.js:24 Uncaught
BindingError
message: "Cannot register public name 'projectPoints' twice"
name: "BindingError"
stack: "BindingError: Cannot register public name 'projectPoints' twice↵ at BindingError. (http://localhost/opencv_js/docs/bin/opencv.js:24:9692639)↵ at new BindingError (eval at createNamedFunction (http://localhost/opencv_js/docs/bin/opencv.js:24:9692348), :4:34)↵ at throwBindingError (http://localhost/opencv_js/docs/bin/opencv.js:24:9697766)↵ at exposePublicSymbol (http://localhost/opencv_js/docs/bin/opencv.js:24:9703298)↵ at __embind_register_function (http://localhost/opencv_js/docs/bin/opencv.js:24:9727605)↵ at wasm-function[802]:8129↵ at wasm-function[75]:373↵ at Module.globalCtors (http://localhost/opencv_js/docs/bin/opencv.js:24:9762125)↵ at func (http://localhost/opencv_js/docs/bin/opencv.js:24:9597365)↵ at callRuntimeCallbacks (http://localhost/opencv_js/docs/bin/opencv.js:24:13606)"
proto: Error

So seems like the overload functions are preventing me from porting them to JavaScript.

Any suggestions please of how I can fix it?

Thanks in advance for your help.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions