// 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;
}
APei
- 粉丝: 79
- 资源: 1万+
最新资源
- (源码)基于Arduino和M5Atom的WiFi CO2监测系统.zip
- (源码)基于Keras的YoloV3目标检测系统.zip
- (源码)基于Spring Boot和MyBatis Plus的手机资产管理系统.zip
- 微信开发者工具(微信小游戏开发引擎)findChildByName全局查找封装
- (源码)基于Python和RealsenseD455的脑外科手术机器人系统.zip
- (源码)基于Java Web的订单管理系统.zip
- (源码)基于Python和Django框架的Jcrontab任务管理系统.zip
- (源码)基于RePlugin插件化框架的动态功能接入系统.zip
- (源码)基于ASP.NET Core的学生教师管理系统.zip
- (源码)基于C++的机房预约管理系统.zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈