2013-02-19 53 views
1

訪問多通道矩陣的第n行通道的語法是什麼?我可以接入信道(I,J);元:: n,而是什麼是使用功能,如行,rowRange,語法.....訪問OpenCV Mat中的多個通道

示例代碼:

Mat M(10, 3, CV_32SC3); 
cout << M.at<Vec3d>(0,0)[1] << endl; // This works 
cout << M.row(0)[1] << endl; // Syntax of this 

回答

2

我認爲你正在尋找如下:

cv::Mat M(10, 3, CV_32SC3); 
cv::Mat_<cv::Vec3d> helpimg = M; 
helpimg .row(0).begin()[0][0] = 2.5; 

我可以編譯它,但我沒有測試它。告訴它是否有效。你可以用它來得到cols值:

helpimg .col(0).begin()[0][0] = 4.5; 
+1

注意,mat.col(0)做了一個深層複製,所以'helpimg .col(0).begin()[0] [0] = 4.5;'不會改變helpimg的內容! (是的,它是行()和col()之間的區別!) – berak 2013-02-19 17:05:58

1

約這樣做什麼:

cout << M.row(0).col(1) << endl; 

Mat::row函數返回一個Mat,這樣你就可以再次調用要麼rowcol的結果,讓你從它需要的行或列。

4
Mat.row(0) returns a Mat, so it's the same game as before: 

// if it's really INT 3channels(like your ex. above), you have to use m.at<Vec3i> !! 
Mat M(10, 3, CV_32SC3); 

// 3rd row 
Mat r = m.row(3);   

// r has only 1 row (3 elems), last pixel there 
cout<< r.at<Vec3i>(0,2)[0];