diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 30fd52c85ace17a9339dcecac08a7862c616b91a..14b44143e84debfc9db3047d3d77d6f0d1caf767 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 0000000000000000000000000000000000000000..7a93b418c61399a8a80f2a98088ce11b8f55e023 --- /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 0000000000000000000000000000000000000000..18cf5ca2f167e783646bbb974831890d29d9a4a6 --- /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 0000000000000000000000000000000000000000..08a869eb443004b074597e7f60e7a60621f06d7c --- /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 0000000000000000000000000000000000000000..bfa0cce083d14baef6dea719b5fd9267a13136d5 --- /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 0000000000000000000000000000000000000000..56b0ae28beda43861934311a274b299a159a4409 --- /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 0000000000000000000000000000000000000000..b79dd9fd0a9bf5be5cd480635739ed7ed857d801 --- /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 22bf08d1a798a07100785af2ee872ceabd77521d..438073dbe6f184b5c52df54dcfe667f20f888e41 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 0000000000000000000000000000000000000000..5f34c321277020e68065dbf9f442525306f261ab --- /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 0000000000000000000000000000000000000000..8817312b9b84a8c0f1a28211fbdb009aef3d8f96 --- /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