Skip to content

UrielCh/opencv-sandbox

Repository files navigation

openCV binding sandbox

Install OpenCV

export OPENCV_BUILD_ROOT to a openCV source workdir.

build openCV and keep sources with:

npm run build-opencv

then duplicate and update your environement in .vscode/c_cpp_properties.json if needed,

in vscode choose the correct C/C++ configuration at the bootom rigth of your screen.

Build NodeJs C++ bindings

node-gyp rebuild; ts-node-cwd.CMD .\src\index.ts

Test the built module

npm run test

Generator

Install the python environment

doc: https://docs.conda.io/projects/conda/en/4.6.0/user-guide/tasks/manage-environments.html

# list availible env:
conda info --envs
# list package in the dedicate env:
conda create --name opencv-sandbox python=3.7
conda list -n opencv-sandbox
conda activate opencv-sandbox

Install the python package locally

pip install -e .

Prepare the headers

Headers should be present somewhere in your opencv install like :

cp ${OPENCV_BUILD_ROOT}/latest/build/modules/python_bindings_generator/headers.txt data/headers.txt
cp ${Env:OPENCV_BUILD_ROOT}/latest/build/modules/python_bindings_generator/headers.txt data/headers.txt

To generate only part of the bindings, you can remove line from data/headers.txt

The minimum data/headers.txt file is

${OPENCV_BUILD_ROOT}/latest/build/modules/core/include/opencv2/core.hpp
${Env:OPENCV_BUILD_ROOT}/latest/build/modules/core/include/opencv2/core.hpp
%OPENCV_BUILD_ROOT%/latest/build/modules/core/include/opencv2/core.hpp

run original generator:

cd ${Env:OPENCV_BUILD_ROOT}/latest/opencv/modules/python/src2
conda activate opencv-sandbox
mkdir dst
python gen2.py dst

Run the generator

Once the headers.txt is ready you can do

mkdir -p cc-generated
python nodejs_opencv_generator/gen2.py cc-generated data/headers.txt

The code whould be visible in cc-generated

References

N-API libbs:

Known errors

on linux you may face Error: libopencv_imgcodecs.so.407: cannot open shared object file: No such file or directory

You can fix it like

export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:${OPENCV_BUILD_ROOT}/latest/build/lib/

About

sandbox to prototype a new N-API binding for openCV

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published