Mat類中的rowRange和colRange 提取某些行或列。
1.首先給出opencv文檔中,對 rowRange和colRange的定義:cv::Mat Class Reference
下面是解釋和翻譯:
函數原型:Mat cv::Mat::colRange(int startcol, int endcol) const
功能:為指定的列跨度創建一個矩陣頭。
該方法為矩陣的指定列跨度創建一個矩陣頭。 類似于Mat :: row和Mat :: col,這是一個O(1)操作
參數:(分別表示我們想取的Mat的第幾列到第幾列)
startcol:一個包含0的起始索引的列跨度。
endcol:一個除0以外的結束索引的列跨度。
函數原型:Mat cv::Mat::colRange(const Range& r) const
功能:這是為了方便起見,它是一個重載的成員函數。 它與上述函數的區別僅在于它接受的參數。
參數:
r:包含開始和結束索引的范圍結構。
rowRange與colRange類似,不再解釋
2.代碼示例:
#include#include #include #include #include #include #include #include using namespace std; using namespace cv; void loadExposureSeq(String, vector &);//加載圖像 int main() { String path = "D:\\project\\StructuredLight_Project\\StructuredLight\\cam\\cam_01\\"; vector images; loadExposureSeq(path, images); return 0; } void loadExposureSeq(String path, vector & images) { ifstream list_file((path + "list.txt").c_str());//文件讀操作,存儲設備讀取到內存中 string name;//txt文件中保存的圖片名字 while (list_file >> name ) { Mat img = imread(path + name); images.push_back(img); imshow("img", img); waitKey(0); } Mat res(576, 5 * 768, CV_8UC3); for (int i = 0; i < 5; i++) { res.colRange(i * 768, (i + 1) * 768) = images[i] +0;//從mat中提取特定列 } imwrite("a.png", res); waitKey(0); list_file.close();//關閉文件流 }