3

Looking to convert a CvMat to numpy array.

1 Answer 1

6

From the OpenCV Python Cookbook:

>>> import cv, numpy                       # Comments added by me
>>> mat = cv.CreateMat(3, 5, cv.CV_32FC1)  # make a 3x5 mat
>>> cv.Set(mat, 7)                         # set the cells to 7
>>> a = numpy.asarray(mat)                 # convert it to a numpy array
>>> print a
[[ 7.  7.  7.  7.  7.]
 [ 7.  7.  7.  7.  7.]
 [ 7.  7.  7.  7.  7.]]

Here is the numpy.asarray documentation.

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.