From caec257000f8ab5a4767c6f20e470e34d4ed48a8 Mon Sep 17 00:00:00 2001 From: Guillaume Pasero <guillaume.pasero@c-s.fr> Date: Wed, 6 Jun 2012 15:43:56 +0200 Subject: [PATCH] ADD: example for the stereo reconstruction chain (WIP) --- ...reorectificationDeformationFieldSource.txx | 1 + Examples/DisparityMap/CMakeLists.txt | 3 + .../StereoReconstructionExample.cxx | 135 ++++++++++++++++++ 3 files changed, 139 insertions(+) create mode 100644 Examples/DisparityMap/StereoReconstructionExample.cxx diff --git a/Code/DisparityMap/otbStereorectificationDeformationFieldSource.txx b/Code/DisparityMap/otbStereorectificationDeformationFieldSource.txx index 8b490b7818..cd65915334 100644 --- a/Code/DisparityMap/otbStereorectificationDeformationFieldSource.txx +++ b/Code/DisparityMap/otbStereorectificationDeformationFieldSource.txx @@ -20,6 +20,7 @@ #include "otbStereorectificationDeformationFieldSource.h" #include "itkProgressReporter.h" +#include "otbMath.h" // For partial specialization #include "otbVectorImage.h" diff --git a/Examples/DisparityMap/CMakeLists.txt b/Examples/DisparityMap/CMakeLists.txt index e1f64592f9..0cc87614fd 100644 --- a/Examples/DisparityMap/CMakeLists.txt +++ b/Examples/DisparityMap/CMakeLists.txt @@ -13,6 +13,9 @@ ADD_EXECUTABLE(FineRegistrationImageFilterExample FineRegistrationImageFilterExa TARGET_LINK_LIBRARIES(FineRegistrationImageFilterExample OTBFeatureExtraction OTBCommon OTBIO ITKIO) +ADD_EXECUTABLE(StereoReconstructionExample StereoReconstructionExample.cxx ) +TARGET_LINK_LIBRARIES(StereoReconstructionExample OTBFeatureExtraction OTBCommon OTBIO +ITKIO) IF( NOT OTB_DISABLE_CXX_TESTING AND BUILD_TESTING ) diff --git a/Examples/DisparityMap/StereoReconstructionExample.cxx b/Examples/DisparityMap/StereoReconstructionExample.cxx new file mode 100644 index 0000000000..28a49f3a95 --- /dev/null +++ b/Examples/DisparityMap/StereoReconstructionExample.cxx @@ -0,0 +1,135 @@ +/*========================================================================= + + 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 : BeginCommandLineArgs +// INPUTS: {sensor_stereo_left.tif}, {sensor_stereo_right.tif} +// OUTPUTS: {elevationOutput.tif} +// 140 +// Software Guide : EndCommandLineArgs + +// Software Guide : BeginLatex +// +// This example demonstrates the use of the stereo reconstruction chain, using the filters : +// \begin{itemize} +// \item \doxygen{otb}{StereorectificationDeformationFieldSource} +// \item \doxygen{otb}{StreamingWarpImageFilter} +// \item \doxygen{otb}{PixelWiseBlockMatchingImageFilter} +// \item \doxygen{otb}{otbSubPixelDisparityImageFilter} +// \item \doxygen{otb}{otbDisparityMapMedianFilter} +// \item \doxygen{otb}{DisparityMapToDEMFilter} +// +// Software Guide : EndLatex + +// Software Guide : BeginCodeSnippet +#include "otbStereorectificationDeformationFieldSource.h" +#include "otbStreamingWarpImageFilter.h" +#include "otbPixelWiseBlockMatchingImageFilter.h" +#include "otbSubPixelDisparityImageFilter.h" +#include "otbDisparityMapMedianFilter.h" +#include "otbDisparityMapToDEMFilter.h" + +#include "otbImage.h" +#include "otbVectorImage.h" +#include "otbImageFileReader.h" +#include "otbStreamingImageFileWriter.h" +#include "otbBCOInterpolateImageFunction.h" +// Software Guide : EndCodeSnippet + + + +int main(int argc, char* argv[]) +{ + if (argc != 5) + { + std::cerr << "Usage: " << argv[0]; + std::cerr << " sensorImage1 sensorImage2 outputDEM "; + std::cerr << "averageElevation " << std::endl; + return EXIT_FAILURE; + } + + typedef otb::Image<float,2> FloatImageType; + typedef otb::VectorImage<float,2> FloatVectorImageType; + + typedef otb::ImageFileReader + <FloatImageType> ImageReaderType; + + typedef otb::StereorectificationDeformationFieldSource + <FloatImageType,FloatVectorImageType> DeformationFieldSourceType; + + typedef itk::Vector<double,2> DeformationType; + typedef otb::Image<DeformationType> DeformationFieldType; + +// typedef itk::VectorCastImageFilter +// <FloatVectorImageType, +// DeformationFieldType> DeformationFieldCastFilterType; + +// typedef itk::InverseDeformationFieldImageFilter +// <DeformationFieldType,DeformationFieldType> InverseDeformationFieldFilterType; + +// typedef itk::VectorIndexSelectionCastImageFilter +// <DeformationFieldType, +// FloatImageType> IndexSelectionCastFilterType; +// +// typedef otb::ImageList<FloatImageType> ImageListType; +// typedef otb::ImageListToVectorImageFilter +// <ImageListType,FloatVectorImageType> ImageListFilterType; +// +// typedef otb::DEMToImageGenerator +// <FloatImageType> DEMToImageGeneratorType; +// typedef otb::StreamingStatisticsImageFilter +// <FloatImageType> StatisticsFilterType; + + double avgElevation = atof(argv[4]); + + ImageReaderType::Pointer leftReader = ImageReaderType::New(); + ImageReaderType::Pointer rightReader = ImageReaderType::New(); + + leftReader->SetFileName(argv[1]); + rightReader->SetFileName(argv[2]); + + DeformationFieldSourceType::Pointer m_DeformationFieldSource = DeformationFieldSourceType::New(); + m_DeformationFieldSource->SetLeftImage(leftReader->GetOutput()); + m_DeformationFieldSource->SetRightImage(rightReader->GetOutput()); + m_DeformationFieldSource->SetGridStep(4); + m_DeformationFieldSource->SetScale(1.0); + m_DeformationFieldSource->SetAverageElevation(avgElevation); + + //m_DeformationFieldSource->Update(); + + + + typedef otb::StreamingImageFileWriter<FloatVectorImageType> WriterType; + WriterType::Pointer leftOutput = WriterType::New(); + WriterType::Pointer rightOutput = WriterType::New(); + + leftOutput->SetInput(m_DeformationFieldSource->GetLeftDeformationFieldOutput()); + rightOutput->SetInput(m_DeformationFieldSource->GetRightDeformationFieldOutput()); + + leftOutput->SetFileName("/home2/gpasero/ORFEO-TOOLBOX/stereo/grid_example_left.tif"); + rightOutput->SetFileName("/home2/gpasero/ORFEO-TOOLBOX/stereo/grid_example_right.tif"); + + leftOutput->Update(); + rightOutput->Update(); + + std::cout << "epi.rectsizex" << m_DeformationFieldSource->GetRectifiedImageSize()[0] << std::endl; + std::cout << "epi.rectsizey" << m_DeformationFieldSource->GetRectifiedImageSize()[1] << std::endl; + std::cout << "epi.baseline" << m_DeformationFieldSource->GetMeanBaselineRatio() << std::endl; + + return EXIT_SUCCESS; +} -- GitLab