如何将CvMat转换为Numpy数组?

时间:2011-08-19 03:50:21

标签: python opencv numpy

希望将CvMat转换为numpy数组。

1 个答案:

答案 0 :(得分:6)

来自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.]]

这是numpy.asarray documentation