0

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?

1

1 Answer 1

1

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);
  1. int parameter: Expects the no. of rows
  2. int parameter: Expects the no. of cols
  3. Type parameter : Expects the type of image.
  4. Void Pointer Parameter: Expects the image data.

And this resolves the problem!!!!.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.