對於OpenCV的1.x中:
您可以使用CreateMat做到這一點:
Creates a matrix header and allocates the matrix data.
Python: cv.CreateMat(rows, cols, type) → mat
Parameters:
rows – Number of rows in the matrix
cols – Number of columns in the matrix
type – The type of the matrix elements in the form CV_<bit depth><S|U|F>C<number of channels> , where S=signed, U=unsigned, F=float. For example, CV _ 8UC1 means the elements are 8-bit unsigned and the there is 1 channel, and CV _ 32SC2 means the elements are 32-bit signed and there are 2 channels.
函數調用等效於以下代碼:
CvMat* mat = cvCreateMatHeader(rows, cols, type);
cvCreateData(mat);
對於CV2接口:
Python的新CV2接口集成numpy陣列到OpenCV的框架,因爲它們是用簡單的多維數組表示,這使得操作更加簡單。 這裏有一個開始的例子:
import numpy as np, cv
vis = np.zeros((384, 836), np.float32)
h,w = vis.shape
vis2 = cv.CreateMat(h, w, cv.CV_32FC3)
vis0 = cv.fromarray(vis)
爲什麼投降? – Newben