Reputation: 119
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 !
Upvotes: 1
Views: 7113
Reputation: 5452
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.
Upvotes: 6