An example of pybind11 for cv::Mat <-> np.array
/project folder
├── build
├── example
│ ├── exemple.so # generate with make
│ └── example.cpython-36m-x86_64-linux-gnu.so # generate with setup.py
├── CMakeLists.txt
├── setup.py
└── ...We use vcpkg to install pybind11 library
Note : This method support opencv 2.4, opencv 3 and opencv 4.
./vcpkg install pybind11
mkdir build
cd build
# configure make with vcpkg toolchain
cmake .. -DCMAKE_TOOLCHAIN_FILE=${VCPKG_DIR}/scripts/buildsystems/vcpkg.cmake
# generate the example.so library
make
# move example.so library in example folder
make installpython3 test.pyNote : This method only support opencv 2.4 and opencv 3 at this time. Opencv 4 is not supported yet.
pip3 install pybind11
python3 setup.py build
python3 setup.py install
or
mv build/lib.linux-x86_64-3.5/example/example.cpython-36m-x86_64-linux-gnu.so example/example.cpython-36m-x86_64-linux-gnu.so
python3 test.py