C++ conversion from NumPy array to Mat (OpenCV)

The best solution in your situation is using custom boost::python converter for cv::Mat object. OpenCV has Python wrapper and when you are using this wrapper you are operating on Numpy arrays – you don’t even need to know that those arrays are converted to cv::Mat objects while “crossing the c++ <-> python border”. Writing such converter for simple type is quite easy, however creating converter for cv::Mat isn’t simple. Fortunetely someone else already did this – here is version for OpenCV 2.x and here for 3.x. If you are not familiar with boost::python converters, this article should help you.
Hope it helps, if you wil have any problems, let us know.

Leave a Comment