diff --git a/Testing/Code/Learning/CMakeLists.txt b/Testing/Code/Learning/CMakeLists.txt index 4e401ce909b98d2ad07c97618837f81879a8226d..b95d0657f8e55f8d293fe40dd05bf2cc1976775a 100644 --- a/Testing/Code/Learning/CMakeLists.txt +++ b/Testing/Code/Learning/CMakeLists.txt @@ -724,6 +724,48 @@ IF(OTB_USE_OPENCV) ${INPUTDATA}/letter.scale ${TEMP}/libsvm_model.txt ) + + ADD_TEST(leTuImageClassificationFilterNew ${LEARNING_TESTS6} + otbImageClassificationFilterNew) + + ADD_TEST(leTvImageClassificationFilterLibSVM ${LEARNING_TESTS6} + --compare-image ${NOTOL} + ${BASELINE}/leSVMImageClassificationFilterOutput.tif + ${TEMP}/leImageClassificationFilterLibSVMOutput.tif + otbImageClassificationFilter + ${INPUTDATA}/ROI_QB_MUL_4.tif + ${INPUTDATA}/svm_model_image + ${TEMP}/leImageClassificationFilterLibSVMOutput.tif + ) + + ADD_TEST(leTvImageClassificationFilterSVM ${LEARNING_TESTS6} + --compare-image ${NOTOL} + ${BASELINE}/leImageClassificationFilterSVMOutput.tif + ${TEMP}/leImageClassificationFilterSVMOutput.tif + otbImageClassificationFilter + ${INPUTDATA}/ROI_QB_MUL_4.tif + ${INPUTDATA}/ROI_QB_MUL_4_svmModel.txt + ${TEMP}/leImageClassificationFilterSVMOutput.tif + ) + + ADD_TEST(leTuLibSVMMachineLearningModelCanRead ${LEARNING_TESTS6} + otbLibSVMMachineLearningModelCanRead + ${INPUTDATA}/svm_model_image + ) + + ADD_TEST(leTuSVMMachineLearningModelCanRead ${LEARNING_TESTS6} + otbSVMMachineLearningModelCanRead + ${INPUTDATA}/svm_model_image + ) + + ADD_TEST(leTuRandomForestsMachineLearningModelCanRead ${LEARNING_TESTS6} + otbRandomForestsMachineLearningModelCanRead + ${TEMP}/RandomForestsMachineLearningModel.txt + ) + SET_TESTS_PROPERTIES(leTuRandomForestsMachineLearningModelCanRead + PROPERTIES DEPENDS leTvRandomForestsMachineLearningModel) + + ENDIF(OTB_USE_OPENCV) # Testing srcs @@ -811,6 +853,8 @@ IF(OTB_USE_OPENCV) SET(BasicLearning_SRCS6 otbLearningTests6.cxx otbTrainMachineLearningModel.cxx + otbImageClassificationFilter.cxx + otbMachineLearningModelCanRead.cxx ) ENDIF(OTB_USE_OPENCV) diff --git a/Testing/Code/Learning/otbLearningTests6.cxx b/Testing/Code/Learning/otbLearningTests6.cxx index 7643f2c0b0f29f1c55d81e82ef642a05d65dd9d6..48d7f42b8cbd069bbbbf8959300dc69467374e1e 100644 --- a/Testing/Code/Learning/otbLearningTests6.cxx +++ b/Testing/Code/Learning/otbLearningTests6.cxx @@ -32,4 +32,9 @@ void RegisterTests() REGISTER_TEST(otbKNearestNeighborsMachineLearningModel); REGISTER_TEST(otbRandomForestsMachineLearningModelNew); REGISTER_TEST(otbRandomForestsMachineLearningModel); + REGISTER_TEST(otbImageClassificationFilterNew); + REGISTER_TEST(otbImageClassificationFilter); + REGISTER_TEST(otbLibSVMMachineLearningModelCanRead); + REGISTER_TEST(otbSVMMachineLearningModelCanRead); + REGISTER_TEST(otbRandomForestsMachineLearningModelCanRead); } diff --git a/Testing/Code/Learning/otbMachineLearningModelCanRead.cxx b/Testing/Code/Learning/otbMachineLearningModelCanRead.cxx new file mode 100644 index 0000000000000000000000000000000000000000..daf4f76c4c2c4ea05f914c689201ff41f7b34254 --- /dev/null +++ b/Testing/Code/Learning/otbMachineLearningModelCanRead.cxx @@ -0,0 +1,109 @@ +/*========================================================================= + + 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. + +=========================================================================*/ + +#include "otbMachineLearningModel.h" +#include "otbLibSVMMachineLearningModel.h" +#include "otbSVMMachineLearningModel.h" +#include "otbRandomForestsMachineLearningModel.h" +#include <iostream> + +typedef otb::MachineLearningModel<float,short> MachineLearningModelType; +typedef MachineLearningModelType::InputValueType InputValueType; +typedef MachineLearningModelType::InputSampleType InputSampleType; +typedef MachineLearningModelType::InputListSampleType InputListSampleType; +typedef MachineLearningModelType::TargetValueType TargetValueType; +typedef MachineLearningModelType::TargetSampleType TargetSampleType; +typedef MachineLearningModelType::TargetListSampleType TargetListSampleType; + +int otbLibSVMMachineLearningModelCanRead(int argc, char* argv[]) +{ + if (argc != 2) + { + std::cerr << "Usage: " << argv[0] + << "<model>" << std::endl; + std::cerr << "Called here with " << argc << " arguments\n"; + for (int i = 1; i < argc; ++i) + { + std::cerr << " - " << argv[i] << "\n"; + } + return EXIT_FAILURE; + } + std::string filename(argv[1]); + typedef otb::LibSVMMachineLearningModel<InputValueType, TargetValueType> SVMType; + SVMType::Pointer classifier = SVMType::New(); + bool lCanRead = classifier->CanReadFile(filename); + if (lCanRead == false) + { + std::cerr << "Erreur otb::LibSVMMachineLearningModel : impossible to open the file " << filename << "." << std::endl; + return EXIT_FAILURE; + } + + return EXIT_SUCCESS; +} + +int otbSVMMachineLearningModelCanRead(int argc, char* argv[]) +{ + if (argc != 2) + { + std::cerr << "Usage: " << argv[0] + << "<model>" << std::endl; + std::cerr << "Called here with " << argc << " arguments\n"; + for (int i = 1; i < argc; ++i) + { + std::cerr << " - " << argv[i] << "\n"; + } + return EXIT_FAILURE; + } + std::string filename(argv[1]); + typedef otb::SVMMachineLearningModel<InputValueType, TargetValueType> SVMType; + SVMType::Pointer classifier = SVMType::New(); + bool lCanRead = classifier->CanReadFile(filename); + if (lCanRead == false) + { + std::cerr << "Erreur otb::SVMMachineLearningModel : impossible to open the file " << filename << "." << std::endl; + return EXIT_FAILURE; + } + + return EXIT_SUCCESS; +} + +int otbRandomForestsMachineLearningModelCanRead(int argc, char* argv[]) +{ + if (argc != 2) + { + std::cerr << "Usage: " << argv[0] + << "<model>" << std::endl; + std::cerr << "Called here with " << argc << " arguments\n"; + for (int i = 1; i < argc; ++i) + { + std::cerr << " - " << argv[i] << "\n"; + } + return EXIT_FAILURE; + } + std::string filename(argv[1]); + typedef otb::RandomForestsMachineLearningModel<InputValueType, TargetValueType> RFType; + RFType::Pointer classifier = RFType::New(); + bool lCanRead = classifier->CanReadFile(filename); + if (lCanRead == false) + { + std::cerr << "Erreur otb::RandomForestsMachineLearningModel : impossible to open the file " << filename << "." << std::endl; + return EXIT_FAILURE; + } + + return EXIT_SUCCESS; +}