python numpy array转置_使用cv.fromarray将转置后的NumPy数组转换为Python中的CvMat类型(Convert transposed NumPy array to ...
I am having a problem where some numpy arrays don't convert to cvMat using cv.fromarray(). It appears the problem occurs whenever the numpy array has been transposed.import numpy as npimport cv# This
I am having a problem where some numpy arrays don't convert to cvMat using cv.fromarray(). It appears the problem occurs whenever the numpy array has been transposed.
import numpy as np
import cv
# This works fine:
b = np.arange(6).reshape(2,3).astype('float32')
B = cv.fromarray(b)
print(cv.GetSize(B))
# But this produces an error:
a = np.arange(6).reshape(3,2).astype('float32')
b = a.T
B = cv.fromarray(b)
print(cv.GetSize(B))
Traceback (most recent call last):
File "", line 1, in
File "test_err.py", line 17, in
B = cv.fromarray(b)
TypeError: cv.fromarray array can only accept arrays with contiguous data
Any suggestions? Many of my arrays have been transposed at some point so the error is coming up frequently.
I'm using Python2.7 on MacOS X Lion with NumPy 1.6.2 and OpenCV 2.4.2.1 installed from MacPorts.
更多推荐



所有评论(0)