2013-09-01 21 views
1

假設我有一個如何提取光柵信息轉換爲通過OpenCV庫處理的格式

vector<unsigned char>a 

這是由GDAL庫RasterIO功能提取的GeoTIFF圖像的光柵信息(一個開源圖書館爲地理信息系統)
我的圖像是一個7697x7309一個所以矢量有56257373成員。
如何在此向量上應用5x5高斯濾波器,然後獲得結果作爲另一個56257373類型爲unsigned char的成員向量,以便能夠使用GDAL庫將向量另存爲另一個geotiff圖像。


我的主要問題是上面的,但如果這是不可能告訴我,如果我有一個文件的GeoTIFF我如何使用OpenCV的在運行時應用上的過濾器。我的意思是我不想將格式轉換爲另一種格式,比如位圖和tiff格式,然後從難以讀取數據的應用程序中讀取數據,假設我在GDAL格式的數據中有一部分內存需要將其轉換爲另一部分中的opencv兼容數據並在其上應用過濾器?

回答

2

我覺得這是你在問什麼:

// 1. Convert vector to Mat 

cv::Mat amat(7309, 7697, CV_8UC1, &a[0]); 

// 2. Apply 5x5 Gaussian filter 

cv::Mat bmat; // blurred output, sigma=1.4 assumed below 
cv::GaussianBlur(amat, bmat, cv::Size(5,5), 1.4); 

// 3. Convert Mat to vector 

cv::Mat cmat = bmat.reshape(1, 1); // make the Mat one big long row 
std::vector<unsigned char>b = cmat; 
0

比矢量簡單<>辦法從GDAL轉換爲OpenCV的柵格數據:

//Region of Interest to be read 
cv::Rect roi(x, y, w, h); 

//Mat allocation to store the data 
cv::Mat mat; 
mat.create(roi.size(),CV_32F); 

//data is stored directly in the mat passing the mat.data pointer to RasterIO 
band->RasterIO(GF_Read, roi.x, roi.y, roi.width, roi.height, mat.data, 
       roi.width, roi.height, GDT_Float32, 0, 0); 

你只是要確保OpenCV數據類型符合GDAL數據類型,並且光柵尺寸的ROI尺寸正常