can not run pipeline.exe properly
I attempted to replicate the Pipeline.exe application based on the tutorial available at https://www.orfeo-toolbox.org/CookBook/C%2B%2B/Examples/Tutorials/Pipeline.html#pipeline-cxx. The application is designed to read an input image file, perform a simple processing pipeline, and write the result to an output image file. However, I encountered issues with setting the input and output filenames in the code.
I followed the tutorial's instructions and used the provided CMake configuration to build the application. Unfortunately, I received error messages indicating that the reader and writer filenames were not set correctly after calling SetFileName.
I performed various debugging steps, including checking file paths, verifying file existence, and updating output information. Despite these efforts, the issue persisted, and the filenames were not being set as expected.
I'm seeking assistance in refining the code to correctly set the input and output filenames, ensuring the successful execution of the OTB pipeline as demonstrated in the tutorial.
here is my pipeline.cxx `#include "otbImage.h" #include "otbImageFileReader.h" #include "otbImageFileWriter.h" #include #include #include #include "itkIndent.h"
int main(int argc, char* argv[]) { // First, check the number of arguments if (argc != 3) { std::cerr << "Usage: " << argv[0] << " <input_filename> <output_filename>" << std::endl; return EXIT_FAILURE; }
try
{
// Declare the image types and reader/writer types
using ImageType = otb::Image<unsigned char, 2>;
using ReaderType = otb::ImageFileReader<ImageType>;
using WriterType = otb::ImageFileWriter<ImageType>;
// Create the reader and writer objects
ReaderType::Pointer reader = ReaderType::New();
WriterType::Pointer writer = WriterType::New();
// Check if the input file exists
std::ifstream infile(argv[1]);
if (!infile.good())
{
std::cerr << "Error: Input file does not exist or is inaccessible: " << argv[1] << std::endl;
return EXIT_FAILURE;
}
infile.close();
// Output the file names for debugging
std::cout << "Input file: " << argv[1] << std::endl;
std::cout << "Output file: " << argv[2] << std::endl;
reader->SetFileName(argv[1]);
writer->SetFileName(argv[2]);
// Debugging: Check if filenames are set correctly
if (reader->GetFileName() == nullptr || std::string(reader->GetFileName()).empty())
{
std::cerr << "Error: Reader filename not set correctly after setting: " << argv[1] << std::endl;
return EXIT_FAILURE;
}
if (writer->GetFileName() == nullptr || std::string(writer->GetFileName()).empty())
{
std::cerr << "Error: Writer filename not set correctly after setting: " << argv[2] << std::endl;
return EXIT_FAILURE;
}
// Connect the reader to the writer
writer->SetInput(reader->GetOutput());
// Trigger the pipeline execution
writer->Update();
}
catch (const std::exception& e)
{
std::cerr << "An error occurred: " << e.what() << std::endl;
return EXIT_FAILURE;
}
return EXIT_SUCCESS;
} ` and here are my outputs
PS C:\Users\zoech\Desktop\example\build\Debug> ./Pipeline.exe "C:\Users\zoech\Downloads\OTB-Data-Examples\Examples\QB_Suburb.png" C:\Users\zoech\Downloads\OTB-Data-ExTB-Data-Examples\Examples\Outpu\output_image.png Input file: C:\Users\zoech\Downloads\OTB-Data-Examples\Examples\QB_Suburb.png Output file: C:\Users\zoech\Downloads\OTB-Data-ExTB-Data-Examples\Examples\Outpu\output_image.png Error: Reader filename not set correctly after setting: C:\Users\zoech\Downloads\OTB-Data-Examples\Examples\QB_Suburb.png
here is my CMakeLists.text cmake_minimum_required(VERSION 3.5) set(CMAKE_BUILD_TYPE Debug) # You can change 'Debug' to 'Release' or other build types project(Tutorials)
find_package(OTB REQUIRED) if(OTB_FOUND) include(${OTB_USE_FILE}) message(STATUS "OTB_USE_FILE: ${OTB_USE_FILE}")
else(OTB_FOUND) message(FATAL_ERROR "Cannot build OTB project without OTB. Please set OTB_DIR.") endif(OTB_FOUND)
add_executable(HelloWorldOTB HelloWorldOTB.cxx ) target_link_libraries(HelloWorldOTB ${OTB_LIBRARIES})
add_executable(Pipeline Pipeline.cxx ) target_link_libraries(Pipeline ${OTB_LIBRARIES}).
I wonder whether is there a problem related to my OTB setup