From b1dae5e4d39fb4597f49e97a97be6f704d50a7f6 Mon Sep 17 00:00:00 2001 From: asantamaria <asantamaria@iri.upc.edu> Date: Wed, 9 Aug 2017 16:26:35 +0200 Subject: [PATCH] added freak descriptor and all previous missing files :( --- src/CMakeLists.txt | 5 +- src/descriptors/freak/descriptor_freak.cpp | 17 +++++ src/descriptors/freak/descriptor_freak.h | 75 +++++++++++++++++++ .../freak/descriptor_freak_load_yaml.cpp | 49 ++++++++++++ src/descriptors/latch/descriptor_latch.cpp | 17 +++++ src/descriptors/latch/descriptor_latch.h | 71 ++++++++++++++++++ .../latch/descriptor_latch_load_yaml.cpp | 48 ++++++++++++ src/examples/test_descriptor.cpp | 6 +- src/examples/yaml/FREAK.yaml | 9 +++ src/examples/yaml/LATCH.yaml | 7 ++ 10 files changed, 300 insertions(+), 4 deletions(-) create mode 100644 src/descriptors/freak/descriptor_freak.cpp create mode 100644 src/descriptors/freak/descriptor_freak.h create mode 100644 src/descriptors/freak/descriptor_freak_load_yaml.cpp create mode 100644 src/descriptors/latch/descriptor_latch.cpp create mode 100644 src/descriptors/latch/descriptor_latch.h create mode 100644 src/descriptors/latch/descriptor_latch_load_yaml.cpp create mode 100644 src/examples/yaml/FREAK.yaml create mode 100644 src/examples/yaml/LATCH.yaml diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 30fd52c..14b4414 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -43,7 +43,9 @@ SET(sources descriptors/akaze/descriptor_akaze.cpp descriptors/akaze/descriptor_akaze_load_yaml.cpp descriptors/latch/descriptor_latch.cpp - descriptors/latch/descriptor_latch_load_yaml.cpp + descriptors/latch/descriptor_latch_load_yaml.cpp + descriptors/freak/descriptor_freak.cpp + descriptors/freak/descriptor_freak_load_yaml.cpp matchers/matcher_base.cpp ) # application header files @@ -76,6 +78,7 @@ SET(headers descriptors/kaze/descriptor_kaze.h descriptors/akaze/descriptor_akaze.h descriptors/latch/descriptor_latch.h + descriptors/freak/descriptor_freak.h matchers/matcher_factory.h matchers/matcher_base.h) diff --git a/src/descriptors/freak/descriptor_freak.cpp b/src/descriptors/freak/descriptor_freak.cpp new file mode 100644 index 0000000..7a93b41 --- /dev/null +++ b/src/descriptors/freak/descriptor_freak.cpp @@ -0,0 +1,17 @@ +#include "descriptor_freak.h" + +namespace vision_utils { + +DescriptorFREAK::DescriptorFREAK(void) +{} + +DescriptorFREAK::~DescriptorFREAK(void) +{} + +} /* namespace vision_utils */ + +// Register in the DescriptorsFactory +namespace vision_utils +{ +VU_REGISTER_DESCRIPTOR("FREAK", DescriptorFREAK); +} /* namespace vision_utils */ diff --git a/src/descriptors/freak/descriptor_freak.h b/src/descriptors/freak/descriptor_freak.h new file mode 100644 index 0000000..18cf5ca --- /dev/null +++ b/src/descriptors/freak/descriptor_freak.h @@ -0,0 +1,75 @@ +#ifndef _DESCRIPTOR_FREAK_H_ +#define _DESCRIPTOR_FREAK_H_ + +#include "../descriptor_base.h" +#include "../descriptor_factory.h" + +// yaml-cpp library +#ifdef USING_YAML + #include <yaml-cpp/yaml.h> +#endif + +namespace vision_utils { + +// Create all pointers +VU_PTR_TYPEDEFS(DescriptorFREAK); +VU_PTR_TYPEDEFS(DescriptorParamsFREAK); + +/** \brief Class parameters + * + */ +struct DescriptorParamsFREAK: public ParamsBase +{ + bool orientationNormalized = true; // Enable orientation normalization. + bool scaleNormalized = true; // Enable scale normalization. + float patternScale = 22.0; // Scaling of the description pattern. + int nOctaves = 4; // Number of octaves covered by the detected keypoints. + std::vector< int > selectedPairs = std::vector< int >(); // (Optional) user defined selected pairs indexes, +}; + +/** \brief DETECTOR class + * + */ +class DescriptorFREAK : public DescriptorBase { + + public: + DescriptorFREAK(); + virtual ~DescriptorFREAK(void); + + // Factory method + static DescriptorBasePtr create(const std::string& _unique_name, const ParamsBasePtr _params); + + private: + + void defineDescriptor(const ParamsBasePtr _params); +}; + +/* + * brief Define detector + */ +inline void DescriptorFREAK::defineDescriptor(const ParamsBasePtr _params) +{ + DescriptorParamsFREAKPtr params_ptr = std::static_pointer_cast<DescriptorParamsFREAK>(_params); + + descriptor_ = cv::xfeatures2d::FREAK::create(params_ptr->orientationNormalized, + params_ptr->scaleNormalized, + params_ptr->patternScale, + params_ptr->nOctaves, + params_ptr->selectedPairs); +} + + +/* + * brief Create object in factory + */ +inline DescriptorBasePtr DescriptorFREAK::create(const std::string& _unique_name, const ParamsBasePtr _params) +{ + DescriptorFREAKPtr det_ptr = std::make_shared<DescriptorFREAK>(); + det_ptr->setName(_unique_name); + det_ptr->defineDescriptor(_params); + return det_ptr; +} + +} /* namespace vision_utils */ + +#endif /* _DESCRIPTOR_FREAK_H_ */ diff --git a/src/descriptors/freak/descriptor_freak_load_yaml.cpp b/src/descriptors/freak/descriptor_freak_load_yaml.cpp new file mode 100644 index 0000000..08a869e --- /dev/null +++ b/src/descriptors/freak/descriptor_freak_load_yaml.cpp @@ -0,0 +1,49 @@ +#include "descriptor_freak.h" + +#ifdef USING_YAML + +// yaml-cpp library +#include <yaml-cpp/yaml.h> + +namespace vision_utils +{ + +namespace +{ + +static ParamsBasePtr createParamsFREAKDescriptor(const std::string & _filename_dot_yaml) +{ + DescriptorParamsFREAKPtr params_ptr = std::make_shared<DescriptorParamsFREAK>(); + + using std::string; + using YAML::Node; + Node yaml_params = YAML::LoadFile(_filename_dot_yaml); + if (!yaml_params.IsNull()) + { + Node d_yaml = yaml_params["descriptor"]; + if(d_yaml["type"].as<string>() == "FREAK") + { + params_ptr->orientationNormalized = d_yaml["orientationNormalized"].as<bool>(); + params_ptr->scaleNormalized = d_yaml["scaleNormalized"].as<bool>(); + params_ptr->patternScale = d_yaml["patternScale"].as<float>(); + params_ptr->nOctaves = d_yaml["nOctaves"].as<int>(); + params_ptr->selectedPairs = d_yaml["selectedPairs"].as<std::vector< int > >(); + }else + { + std::cerr << "Bad configuration file. Wrong type " << d_yaml["type"].as<string>() << std::endl; + return nullptr; + } + } + + return params_ptr; +} + +// Register in the SensorFactory +const bool registered_desFREAK_params = ParamsFactory::get().registerCreator("FREAK DES", createParamsFREAKDescriptor); + +} /* namespace [unnamed] */ + +} /* namespace vision_utils */ + +#endif /* IF USING_YAML */ + diff --git a/src/descriptors/latch/descriptor_latch.cpp b/src/descriptors/latch/descriptor_latch.cpp new file mode 100644 index 0000000..bfa0cce --- /dev/null +++ b/src/descriptors/latch/descriptor_latch.cpp @@ -0,0 +1,17 @@ +#include "descriptor_latch.h" + +namespace vision_utils { + +DescriptorLATCH::DescriptorLATCH(void) +{} + +DescriptorLATCH::~DescriptorLATCH(void) +{} + +} /* namespace vision_utils */ + +// Register in the DescriptorsFactory +namespace vision_utils +{ +VU_REGISTER_DESCRIPTOR("LATCH", DescriptorLATCH); +} /* namespace vision_utils */ diff --git a/src/descriptors/latch/descriptor_latch.h b/src/descriptors/latch/descriptor_latch.h new file mode 100644 index 0000000..56b0ae2 --- /dev/null +++ b/src/descriptors/latch/descriptor_latch.h @@ -0,0 +1,71 @@ +#ifndef _DESCRIPTOR_LATCH_H_ +#define _DESCRIPTOR_LATCH_H_ + +#include "../descriptor_base.h" +#include "../descriptor_factory.h" + +// yaml-cpp library +#ifdef USING_YAML + #include <yaml-cpp/yaml.h> +#endif + +namespace vision_utils { + +// Create all pointers +VU_PTR_TYPEDEFS(DescriptorLATCH); +VU_PTR_TYPEDEFS(DescriptorParamsLATCH); + +/** \brief Class parameters + * + */ +struct DescriptorParamsLATCH: public ParamsBase +{ + int bytes = 32; // Size of the descriptor - can be 64, 32, 16, 8, 4, 2 or 1 + bool rotationInvariance = true; // Whether or not the descriptor should compansate for orientation changes + int half_ssd_size = 3; // Size of half of the mini-patches size +}; + +/** \brief DETECTOR class + * + */ +class DescriptorLATCH : public DescriptorBase { + + public: + DescriptorLATCH(); + virtual ~DescriptorLATCH(void); + + // Factory method + static DescriptorBasePtr create(const std::string& _unique_name, const ParamsBasePtr _params); + + private: + + void defineDescriptor(const ParamsBasePtr _params); +}; + +/* + * brief Define detector + */ +inline void DescriptorLATCH::defineDescriptor(const ParamsBasePtr _params) +{ + DescriptorParamsLATCHPtr params_ptr = std::static_pointer_cast<DescriptorParamsLATCH>(_params); + + descriptor_ = cv::xfeatures2d::LATCH::create(params_ptr->bytes, + params_ptr->rotationInvariance, + params_ptr->half_ssd_size); +} + + +/* + * brief Create object in factory + */ +inline DescriptorBasePtr DescriptorLATCH::create(const std::string& _unique_name, const ParamsBasePtr _params) +{ + DescriptorLATCHPtr det_ptr = std::make_shared<DescriptorLATCH>(); + det_ptr->setName(_unique_name); + det_ptr->defineDescriptor(_params); + return det_ptr; +} + +} /* namespace vision_utils */ + +#endif /* _DESCRIPTOR_LATCH_H_ */ diff --git a/src/descriptors/latch/descriptor_latch_load_yaml.cpp b/src/descriptors/latch/descriptor_latch_load_yaml.cpp new file mode 100644 index 0000000..b79dd9f --- /dev/null +++ b/src/descriptors/latch/descriptor_latch_load_yaml.cpp @@ -0,0 +1,48 @@ +#include "descriptor_latch.h" + +#ifdef USING_YAML + +// yaml-cpp library +#include <yaml-cpp/yaml.h> + +namespace vision_utils +{ + +namespace +{ + +static ParamsBasePtr createParamsLATCHDescriptor(const std::string & _filename_dot_yaml) +{ + DescriptorParamsLATCHPtr params_ptr = std::make_shared<DescriptorParamsLATCH>(); + + using std::string; + using YAML::Node; + Node yaml_params = YAML::LoadFile(_filename_dot_yaml); + if (!yaml_params.IsNull()) + { + Node d_yaml = yaml_params["descriptor"]; + if(d_yaml["type"].as<string>() == "LATCH") + { + params_ptr->bytes = d_yaml["bytes"].as<int>(); + params_ptr->rotationInvariance = d_yaml["rotationInvariance"].as<bool>(); + params_ptr->half_ssd_size = d_yaml["half_ssd_size"].as<int>(); + + }else + { + std::cerr << "Bad configuration file. Wrong type " << d_yaml["type"].as<string>() << std::endl; + return nullptr; + } + } + + return params_ptr; +} + +// Register in the SensorFactory +const bool registered_desLATCH_params = ParamsFactory::get().registerCreator("LATCH DES", createParamsLATCHDescriptor); + +} /* namespace [unnamed] */ + +} /* namespace vision_utils */ + +#endif /* IF USING_YAML */ + diff --git a/src/examples/test_descriptor.cpp b/src/examples/test_descriptor.cpp index 22bf08d..438073d 100644 --- a/src/examples/test_descriptor.cpp +++ b/src/examples/test_descriptor.cpp @@ -29,7 +29,7 @@ #include "../descriptors/kaze/descriptor_kaze.h" #include "../descriptors/akaze/descriptor_akaze.h" #include "../descriptors/latch/descriptor_latch.h" -//#include "../descriptors/freak/descriptor_freak.h" +#include "../descriptors/freak/descriptor_freak.h" //#include "../descriptors/brief/descriptor_brief.h" //#include "../descriptors/daisy/descriptor_daisy.h" //#include "../descriptors/lucid/descriptor_lucid.h" @@ -104,8 +104,8 @@ int main(void) des_ptr = std::static_pointer_cast<DescriptorAKAZE>(des_ptr); else if (des_name.compare("LATCH") == 0) des_ptr = std::static_pointer_cast<DescriptorLATCH>(des_ptr); -// else if (des_name.compare("FREAK") == 0) -// des_ptr = std::static_pointer_cast<DescriptorFREAK>(des_ptr); + else if (des_name.compare("FREAK") == 0) + des_ptr = std::static_pointer_cast<DescriptorFREAK>(des_ptr); // else if (des_name.compare("BRIEF") == 0) // des_ptr = std::static_pointer_cast<DescriptorBRIEF>(des_ptr); // else if (des_name.compare("DAISY") == 0) diff --git a/src/examples/yaml/FREAK.yaml b/src/examples/yaml/FREAK.yaml new file mode 100644 index 0000000..5f34c32 --- /dev/null +++ b/src/examples/yaml/FREAK.yaml @@ -0,0 +1,9 @@ +sensor: + type: "USB_CAM" +descriptor: + type: "FREAK" + orientationNormalized: true + scaleNormalized: true + patternScale: 22.0 + nOctaves: 4 + selectedPairs: [] \ No newline at end of file diff --git a/src/examples/yaml/LATCH.yaml b/src/examples/yaml/LATCH.yaml new file mode 100644 index 0000000..8817312 --- /dev/null +++ b/src/examples/yaml/LATCH.yaml @@ -0,0 +1,7 @@ +sensor: + type: "USB_CAM" +descriptor: + type: "LATCH" + bytes: 32 + rotationInvariance: true + half_ssd_size: 3 \ No newline at end of file -- GitLab