我有一个问题,其中一些numpy数组不使用cv.fromarray()转换为cvMat.只要numpy数组被转置,就会出现问题.
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
有什么建议?我的许多阵列都在某些时候进行了转换,因此错误频繁出现.
我在MacOS X Lion上使用Python2.7,从MacPorts安装了NumPy 1.6.2和OpenCV 2.4.2.1.