How to use opencv's C++ functions for interfacing with numpy?


I’ve been writing a C++ library that uses openCV and interfaces with python.

My idea is to use the Mat to numpyArray conversor from /modules/python/src2 but I am not sure if these functions are compiled/linked against libopencv_core and how to import them.

All in all, can you hint me into converting a cv::Matinto a NumPy array ?

when in doubt, work with Cython. it doesn’t know what a cv::Mat is but it can turn the usual data formats into numpy arrays

I’m not sure OpenCV’s python bindings voodoo was made to be reused by others. there have been discussions in the past where people appear to have reused that magic for their own use cases, like you intend to do.

Sounds like a nice project proposal then :slight_smile:

I’ll try hacking around. Thanks for the reply !

just out of curiosity:
why is there such a hybrid (c++/ py) approach ?
what is your “use-case” ?

Well, I am transitioning a project from python to C++.
My approach is to not only rewrite the app but also wrap some functions to python, making sure that the app still behaves correctly.

In the python side, I import a module that overloads the pure-python implementation.

In the C++ side, the app/library also generates a python extension.

1 Like