I am reading an image in Python and passing that numpy array to C++ using Boost.Python and receiving that in ndarray
.
I need to convert the same into cv::Mat
to perform operations in OpenCV C++.
How do I do that?
Finally I found the solution for that from the documentations:
We Have to receive the numpy array as numeric::array
in C++ and have to do the following steps to easily convert the numpy into cv::mat
efficiently.
void* img_arr = PyArray_DATA((PyObject*)arr.ptr());
And we need to pass this void ptr to the cv::Mat Constructor with other parameters required.
Mat image(rows, cols , CV_8UC3, img_arr);
And this resolves the problem!!!!.