看了网上众多的资料,发现gdal对于图像处理不是那么的方便,遂选择使用opencv实现对图像的处理,但是opencv对于图像格式的灵活度又没有gdal来的这么方便,所以将两者结合,实现最终图像处理的目的。
这里主要贴上两个函数。
第一个是将图像用GDAL读进来,然后转换成opencv的Mat型,便可以对图像的行列进行灵活的处理。
第二个函数是将Mat类型的图像,转换成GDAL,然后再保存出来。
#include <iostream>
#include <gdal.h>
#include <gdal_priv.h>
#include <opencv.hpp>
using namespace std;
using namespace cv;
struct Info
{
double adfGeoTransform[6] = {
0 };
const char* proj = "";
};
Mat GdaltoMat(const char*filename,Info &St);
bool MatToFile(Mat dst, Info &St, const char*outputpath);
int main()
{
const char*img = "D:\\img.tif";
const char*pdst = "D:\\pdst.tif";
Info St;
Mat dst=GdaltoMat(img, St);
MatToFile(dst, St, pdst);
return 0;
}
Mat GdaltoMat(const char*filename,Info &St