Commit c54a715f authored by Manuel Grizonnet's avatar Manuel Grizonnet

DOC:RPC to sensor model example v0

parent 7ea14993
......@@ -34,6 +34,8 @@ TARGET_LINK_LIBRARIES(VectorDataProjectionExample OTBProjections OTBCommon OTBIO
ADD_EXECUTABLE(VectorDataExtractROIExample VectorDataExtractROIExample.cxx )
TARGET_LINK_LIBRARIES(VectorDataExtractROIExample OTBProjections OTBCommon OTBIO)
ADD_EXECUTABLE(EstimateRPCSensorModelExample EstimateRPCSensorModelExample.cxx )
TARGET_LINK_LIBRARIES(EstimateRPCSensorModelExample OTBProjections OTBCommon OTBIO)
IF( NOT OTB_DISABLE_CXX_TESTING AND BUILD_TESTING )
......@@ -110,6 +112,35 @@ ADD_TEST(prTeVectorDataProjectionExampleTest ${EXE_TESTS}
)
ENDIF(OTB_DATA_USE_LARGEINPUT)
IF(OTB_DATA_USE_LARGEINPUT)
#TODO change the example by using a SPOT4 roamnia
ADD_TEST(prTvEstimateRPCSensorModelExampleTest ${EXE_TESTS}
--compare-ascii ${EPSILON_4}
${BASELINE}/otbGCPsToRPCSensorModelImageFilterWithoutDEMOutput.txt
${TEMP}/otbGCPsToRPCSensorModelImageFilterWithoutDEMOutput.txt
EstimateRPCSensorModelExampleTest
${LARGEINPUT}/SPOT4/RIO_DE_JANEIRO/IMAG_01.DAT
${TEMP}/otbGCPsToRPCSensorModelImageFilterWithoutDEMOutput.txt
1199 1259 -22.76847 -43.168043 0.
1497 727 -22.688931 -43.066686 0.
699 1146 -22.7254 -43.288651 0.
1379 2457 -22.986073 -43.193502 0.
2592 1846 -22.932684 -42.854215 0.
1430 1797 -22.872988 -43.136813 0.
587 2654 -22.983847 -43.393297 0.
2398 2422 -23.025664 -42.928778 0.
1436 2946 -23.074483 -43.192431 0.
963 2915 -23.047382 -43.310011 0.
1081 1024 -22.721919 -43.18523 0.
1395 1213 -22.769191 -43.116752 0.
1781 2202 -22.959556 -43.069911 0.
2803 1942 -22.958868 -42.808235 0.
980 2734 -22.99534 -43.309672 0.
713 2754 -23.007862 -43.365307 0.
)
ENDIF(OTB_DATA_USE_LARGEINPUT)
IF( OTB_USE_CURL )
ADD_TEST(prTePlaceNameToLonLatExampleTest ${EXE_TESTS2}
PlaceNameToLonLatExampleTest
......
/*=========================================================================
Program: ORFEO Toolbox
Language: C++
Date: $Date$
Version: $Revision$
Copyright (c) Centre National d'Etudes Spatiales. All rights reserved.
See OTBCopyright.txt for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notices for more information.
=========================================================================*/
// Software Guide : BeginLatex
//
// \index{otb::GCPsToRPCSensorModelImageFilter}
// \index{otb::GCPsToRPCSensorModelImageFilter!header}
//
//
// The following example illustrates the application of estimation
// of a sensor model to an image (limited to a RPC sensor model for now).
// The \doxygen{otb}{GCPsToRPCSensorModelImageFilter} estimates an RPC
// sensor model from a list of user defined GCPs. Internally, it uses
// an ossimRpcSolver, which performs the estimation using the well
// known least-square method.
// Let's look at the minimal code required to use this
// algorithm. First, the following header defining the
// \doxygen{otb}{GCPsToRPCSensorModelImageFilter} class must be
// included.
// Software Guide : EndLatex
// Software Guide : BeginCodeSnippet
//#include "otbMacro.h"
#include "otbImage.h"
#include "otbImageFileReader.h"
#include "otbGCPsToRPCSensorModelImageFilter.h"
// Software Guide : EndCodeSnippet
int main( int argc, char* argv[] )
{
if(argc < 3 )
{
std::cerr<<"Usage: "<<argv[0]<<" infname outfname a1x a1y b1x b1y b1z ... aNx aNy bNx bNy bNz"<<std::endl;
return EXIT_FAILURE;
}
else if((argc-3)%5 != 0)
{
std::cerr<<"Inconsistent GCPs description!"<<std::endl;
return EXIT_FAILURE;
}
const char * infname = argv[1];
const char * outfname = argv[2];
// Software Guide : BeginLatex
//
// We declare the image type based on a particular pixel type and
// dimension. In this case the \code{float} type is used for the pixels.
//
// Software Guide : EndLatex
// Software Guide : BeginCodeSnippet
typedef otb::Image<float, 2> ImageType;
typedef otb::ImageFileReader<ImageType> ReaderType;
typedef otb::GCPsToRPCSensorModelImageFilter<ImageType> GCPsToSensorModelFilterType;
typedef GCPsToSensorModelFilterType::Point2DType Point2DType;
typedef GCPsToSensorModelFilterType::Point3DType Point3DType;
// Software Guide : EndCodeSnippet
// We instantiate reader and writer types
ReaderType::Pointer reader = ReaderType::New();
reader->SetFileName(infname);
// Software Guide : BeginLatex
//
// The \doxygen{otb}{GCPsToRPCSensorModelImageFilter} is instantiated.
//
// Software Guide : EndLatex
// Software Guide : BeginCodeSnippet
GCPsToSensorModelFilterType::Pointer rpcEstimator = GCPsToSensorModelFilterType::New();
rpcEstimator->SetInput(reader->GetOutput());
// Software Guide : EndCodeSnippet
// Software Guide : BeginLatex
// We retrieve the command line parameters and put them in the
// correct variables. Firstl, We determine the number of GCPs
// set from the command line parameters and they are stored in:
// \begin{itemize}
// \item \doxygen{otb}{Point3DType} : Store the sensor point (3D ground point)
// \item \doxygen{otb}{Point2DType} : Pixel assotiated in the image (2D physical coordinates)
// Here we do not use DEM or MeanElevation. It is also possible to give a 2D
// ground point and use the DEM or MeanElevation to get
// the corresponding elevation.
// \end{itemize}
// Software Guide : EndLatex
// Software Guide : BeginCodeSnippet
unsigned int nbGCPs = (argc-3)/5;
std::cout<<"Receiving "<<nbGCPs<<" from command line."<<std::endl;
for(unsigned int gcpId = 0;gcpId<nbGCPs;++gcpId)
{
Point2DType sensorPoint;
sensorPoint[0] = atof(argv[3+gcpId*5]);
sensorPoint[1] = atof(argv[4+gcpId*5]);
Point3DType geoPoint;
geoPoint[0] = atof(argv[5+5*gcpId]);
geoPoint[1] = atof(argv[6+5*gcpId]);
geoPoint[2] = atof(argv[7+5*gcpId]);
std::cout<<"Adding GCP sensor: "<<sensorPoint<<" <-> geo: "<<geoPoint<<std::endl;
rpcEstimator->AddGCP(sensorPoint,geoPoint);
}
// Software Guide : BeginLatex
// Note that the \doxygen{otb}{GCPsToRPCSensorModelImageFilter} needs
// at least 16 GCPs to estimate a proper RPC sensor model,
// although no warning will be reported to the user if
// the number of GCPs is lower than 16.
// Actual estimation of the sensor model takes place in the
// \code{GenerateOutputInformation()} method.
// Software Guide : EndLatex
// Software Guide : BeginCodeSnippet
rpcEstimator->GetOutput()->UpdateOutputInformation();
// Software Guide : EndCodeSnippet
// Software Guide : BeginLatex
// The result of the RPC model estimation and the residual ground
// error is then save in a txt file. Note that This filter does
// not modify the image buffer, but only the metadata.
// Software Guide : EndLatex
// Software Guide : BeginCodeSnippet
std::ofstream ofs;
ofs.open(outfname);
// Set floatfield to format properly
ofs.setf(ios::fixed, ios::floatfield);
ofs.precision(10);
ofs<<(ImageType::Pointer)rpcEstimator->GetOutput()<<std::endl;
ofs<<"Residual ground error: "<<rpcEstimator->GetResidualGroundError()<<std::endl;
ofs.close();
// Software Guide : EndCodeSnippet
// Software Guide : BeginLatex
// The output image can be now given to the \doxygen{otb}{orthorectificationFilter}.
// Software Guide : EndLatex
return EXIT_SUCCESS;
}
......@@ -28,6 +28,7 @@ void RegisterTests()
{
REGISTER_TEST(PlaceNameToLonLatExampleTest);
REGISTER_TEST(CoordinateToNameExampleTest);
REGISTER_TEST(EstimateRPCSensorModelExampleTest);
}
......@@ -38,3 +39,7 @@ void RegisterTests()
#undef main
#define main CoordinateToNameExampleTest
#include "CoordinateToNameExample.cxx"
#undef main
#define main EstimateRPCSensorModelExampleTest
#include "EstimateRPCSensorModelExample.cxx"
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment