1

I am using Python 2.7 and opencv 2.1.

I have a numpy array and I want to convert it to an opencv matrix of type "cv.CV_32FC1". How can I set the type ?

"CreateMat()" allows for explicit type setting but "fromarray()" doesnt. If I just apply fromarray on a float array the type check fails (one of the next modules performs a specific type check for CV_32FC1)

thanks !

1 Answer 1

6

You can try the following:

dest = cv.createMat(r, c, cv.CV_32FC1)
src = cv.fromarray(your_np_array)
cv.Convert(src, dest)

where your numpy array has r rows and c columns.

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.