// proj0313.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include "rpc.h"
#include "rpcResample.h"
#include "gdal_priv.h"
#pragma comment(lib, "gdal_i.lib")
bool SaveImageToFile(char *szPath,unsigned char* img,int nSamples,int nLines,int nBandCount,const char *pszFormat ="GTiff")
{
GDALAllRegister(); //利用GDAL读取图片,先要进行注册
CPLSetConfigOption("GDAL_FILENAME_IS_UTF8","NO"); //设置支持中文路径
//准备保存图片
GDALDriver *poDriver=GetGDALDriverManager()->GetDriverByName(pszFormat);
if( poDriver == NULL )
{
return false;
}
char **papszOptions = NULL;
GDALDataset *WriteDataSet = poDriver->Create(szPath, nSamples,nLines,nBandCount,GDT_Byte,papszOptions);
if(WriteDataSet->RasterIO(GF_Write,0,0,nSamples,nLines,img,nSamples,nLines,GDT_Byte,nBandCount,NULL,0,0,0)==CE_Failure )
{
return false;
}
delete WriteDataSet;WriteDataSet=NULL;
return true;
}
int _tmain(int argc, _TCHAR* argv[])
{
RPCpara rpc1, rpc10, rpc2, rpc20, rpc3, rpc30;
readRPC(rpc1,"E:\\Data\\test_for_epipolar\\nav.txt");
readRPC(rpc10,"E:\\Data\\test_for_epipolar\\nav_ref.txt");
readRPC(rpc2,"E:\\Data\\test_for_epipolar\\fav.txt");
readRPC(rpc20,"E:\\Data\\test_for_epipolar\\fav_ref.txt");
readRPC(rpc3,"E:\\Data\\test_for_epipolar\\bav.txt");
readRPC(rpc30,"E:\\Data\\test_for_epipolar\\bav_ref.txt");
rpcResample<unsigned char> toResample;
GDALDataset *poDataset1,*poDataset2,*poDataset3;
int width1, height1, bandCount1;
int width2, height2, bandCount2;
int width3, height3, bandCount3;
GDALRasterBand *poBand1, *poBand2, *poBand3;
GDALDataType dataType1, dataType2, dataType3;
unsigned char *pIm1_UInt8 = NULL, *pIm2_UInt8 = NULL, *pIm3_UInt8 = NULL;
GDALAllRegister();
poDataset1 = (GDALDataset *) GDALOpen( "E:\\Data\\test_for_epipolar\\nav.tif", GA_ReadOnly );
poDataset2 = (GDALDataset *) GDALOpen( "E:\\Data\\test_for_epipolar\\fav.tif", GA_ReadOnly );
poDataset3 = (GDALDataset *) GDALOpen( "E:\\Data\\test_for_epipolar\\bav.tif", GA_ReadOnly );
if(!poDataset1 || !poDataset2 || !poDataset2) return -1;
width1 = poDataset1->GetRasterXSize();
height1 = poDataset1->GetRasterYSize();
bandCount1 = poDataset1->GetRasterCount();
width2 = poDataset2->GetRasterXSize();
height2 = poDataset2->GetRasterYSize();
bandCount2 = poDataset2->GetRasterCount();
width3 = poDataset3->GetRasterXSize();
height3 = poDataset3->GetRasterYSize();
bandCount3 = poDataset3->GetRasterCount();
if (bandCount1 == 1 && bandCount2 == 1 && bandCount3 == 1)
{
poBand1 = poDataset1->GetRasterBand(1);
poBand2 = poDataset2->GetRasterBand(1);
poBand3 = poDataset3->GetRasterBand(1);
dataType1 = poBand1->GetRasterDataType();
dataType2 = poBand2->GetRasterDataType();
dataType3 = poBand3->GetRasterDataType();
if (dataType1 == GDT_Byte && dataType2 == GDT_Byte && dataType3 == GDT_Byte)
{
pIm1_UInt8 = new unsigned char[width1*height1];
pIm2_UInt8 = new unsigned char[width1*height1];
pIm3_UInt8 = new unsigned char[width1*height1];
poBand1->RasterIO(GF_Read,0,0,width1,height1,pIm1_UInt8,width1,height1,GDT_Byte,0,0);
poBand2->RasterIO(GF_Read,0,0,width2,height2,pIm2_UInt8,width2,height2,GDT_Byte,0,0);
poBand3->RasterIO(GF_Read,0,0,width3,height3,pIm3_UInt8,width3,height3,GDT_Byte,0,0);
toResample.initialize1(pIm1_UInt8,height1,width1,rpc1);
toResample.initialize2(pIm2_UInt8,height2,width2,rpc2);
toResample.setGeoPara(112.590954177137035686,23.557627080210959747,300,0,2.5,112.590954177137035686);
toResample.calcResamplePara(12288,12258,rpc10,rpc20);
toResample.resample();
SaveImageToFile("E:\\Data\\test_for_epipolar\\nav_epi.tif",toResample.getEpIm1(),toResample.getEpImWidth(),toResample.getEpImHeight(),1,"GTiff");
SaveImageToFile("E:\\Data\\test_for_epipolar\\fav_epi.tif",toResample.getEpIm2(),toResample.getEpImWidth(),toResample.getEpImHeight(),1,"GTiff");
toResample.deleteEpiIm();
delete []pIm1_UInt8;
delete []pIm2_UInt8;
delete []pIm3_UInt8;
}
}
GDALClose((GDALDatasetH)poDataset1);
GDALClose((GDALDatasetH)poDataset2);
GDALClose((GDALDatasetH)poDataset3);
return 0;
}
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
对于高分辨率遥感卫星数据而言,目前几乎都提供了有理函数模型(RFM)来进行图像校正(SPOT系列提供了有理函数模型之外还提供了严格轨道模型)。对遥感影像进行校正目前最常用的就是使用有理函数模型来进行校正。
资源推荐
资源详情
资源评论
收起资源包目录
rpc.zip (4个子文件)
proj0313.cpp 4KB
rpcResample.h 7KB
projection.h 4KB
rpc.h 20KB
共 4 条
- 1
资源评论
- 2301_765181362023-11-05果断支持这个资源,资源解决了当前遇到的问题,给了新的灵感,感谢分享~
APei
- 粉丝: 81
- 资源: 1万+
下载权益
C知道特权
VIP文章
课程特权
开通VIP
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功