1.一般的Mat定義方法:cv::Mat M(height,width,<Type>),例:
cv::Mat M(480,640,CV_8UC3); 表示定義了一個480行640列的矩陣,矩陣的每個單元的由三個(C3:3 Channel)8位無符號整形(U Unsigned U8 8位)構成。
2.將已有數組賦給Mat矩陣的方法:
cv::Mat M = cv::Mat(height,width,<Type>,data),例:
float K[3][3] = {fc[0], 0, cc[0], 0, fc[1], cc[1], 0, 0, 1}; //攝像機內參數矩陣K cv::Mat mK = cv::Mat(3,3,CV_32FC1,K); //內參數K Mat類型變量
3.類似matlab:zeros(),ones(),eyes()的初始化方法:
cv::Mat M = cv::Mat::eye(height,width,<Type>)
cv::Mat M = cv::Mat::ones(height,width,<Type>)
cv::Mat M = cv::Mat::zeros(height,width,<Type>)
4.對於小矩陣給定數值的賦值方法:
cv::Mat M = (cv::Mat_<Type>(height,width) << 0,-1,0,-1,5,-1,0,-1,0)
得到以下矩陣 M=
[0 -1 0
-1 5 -1
0 -1 0]
詳細介紹請參考官網相關部分鏈接:http://docs.opencv.org/doc/tutorials/core/mat_the_basic_image_container/mat_the_basic_image_container.html