2015-12-24 72 views
0

我有一個矩陣a類型CV_32FC2將「CV_32FC2」類型的矩陣轉換爲類型「CV_32FC1」

我試圖將它轉換成一個新的矩陣b與類型CV_32FC1,但似乎矩陣b也得到CV_32FC2

代碼示例和輸出:

cv::Mat b; 
a.convertTo(b, CV_32FC1); 
std::cout << a.type() << " " << b.type() << std::endl; 

產生輸出:

13 13 

我期望的b類型改變到5,這是鑑於CV_32FC1

+0

在http://docs.opencv.org/2.4/modules/core/doc /basic_structures.html#mat-convertto它表示*「rtype - 所需的輸出矩陣類型,或者說,深度,因爲通道數量與輸入有;「*。 –

+0

你是什麼意思下的「轉換」,拆分渠道,重塑或其他...? –

+0

converTo轉換類型(例如,從float到uchar),而不是通道數量。使用重塑:「b = a.reshape(1);」 – Miki

回答

5

枚舉值CV_32FC2類型的矩陣A,又名Mat2f

Mat2f A(3,2); 
randu(A, Scalar(0, 0), Scalar(1,1)); 

enter image description here

你可以得到一個矩陣BCV_32FC1型,又名Mat1f使用reshape

Mat1f B = A.reshape(1); 

enter image description here

兩個矩陣CV_32FC1使用split(通過@的建議Micka在評論中):

vector<Mat1f> CC; 
split(A, CC); 

其中CC[0]是:

enter image description here

CC[1]是:

enter image description here