From 2255568173be550c10ed566b9e7fd06df2c3984d Mon Sep 17 00:00:00 2001 From: asantamaria <asantamaria@iri.upc.edu> Date: Wed, 9 Aug 2017 17:31:55 +0200 Subject: [PATCH] added lucid descriptor --- src/CMakeLists.txt | 3 + src/descriptors/lucid/descriptor_lucid.cpp | 17 +++++ src/descriptors/lucid/descriptor_lucid.h | 69 +++++++++++++++++++ .../lucid/descriptor_lucid_load_yaml.cpp | 46 +++++++++++++ src/examples/test_descriptor.cpp | 9 ++- src/examples/yaml/LUCID.yaml | 6 ++ 6 files changed, 147 insertions(+), 3 deletions(-) create mode 100644 src/descriptors/lucid/descriptor_lucid.cpp create mode 100644 src/descriptors/lucid/descriptor_lucid.h create mode 100644 src/descriptors/lucid/descriptor_lucid_load_yaml.cpp create mode 100644 src/examples/yaml/LUCID.yaml diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index a03903d..a4a52dc 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -50,6 +50,8 @@ SET(sources descriptors/brief/descriptor_brief_load_yaml.cpp descriptors/daisy/descriptor_daisy.cpp descriptors/daisy/descriptor_daisy_load_yaml.cpp + descriptors/lucid/descriptor_lucid.cpp + descriptors/lucid/descriptor_lucid_load_yaml.cpp matchers/matcher_base.cpp ) # application header files @@ -85,6 +87,7 @@ SET(headers descriptors/freak/descriptor_freak.h descriptors/brief/descriptor_brief.h descriptors/daisy/descriptor_daisy.h + descriptors/lucid/descriptor_lucid.h matchers/matcher_factory.h matchers/matcher_base.h) diff --git a/src/descriptors/lucid/descriptor_lucid.cpp b/src/descriptors/lucid/descriptor_lucid.cpp new file mode 100644 index 0000000..42bbd7a --- /dev/null +++ b/src/descriptors/lucid/descriptor_lucid.cpp @@ -0,0 +1,17 @@ +#include "descriptor_lucid.h" + +namespace vision_utils { + +DescriptorLUCID::DescriptorLUCID(void) +{} + +DescriptorLUCID::~DescriptorLUCID(void) +{} + +} /* namespace vision_utils */ + +// Register in the DescriptorsFactory +namespace vision_utils +{ +VU_REGISTER_DESCRIPTOR("LUCID", DescriptorLUCID); +} /* namespace vision_utils */ diff --git a/src/descriptors/lucid/descriptor_lucid.h b/src/descriptors/lucid/descriptor_lucid.h new file mode 100644 index 0000000..148021a --- /dev/null +++ b/src/descriptors/lucid/descriptor_lucid.h @@ -0,0 +1,69 @@ +#ifndef _DESCRIPTOR_LUCID_H_ +#define _DESCRIPTOR_LUCID_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(DescriptorLUCID); +VU_PTR_TYPEDEFS(DescriptorParamsLUCID); + +/** \brief Class parameters + * + */ +struct DescriptorParamsLUCID: public ParamsBase +{ + int lucid_kernel = 1; // Kernel for descriptor construction, where 1=3x3, 2=5x5, 3=7x7 and so forth + int blur_kernel = 2; // Kernel for blurring image prior to descriptor construction, where 1=3x3, 2=5x5, 3=7x7 and so forth +}; + +/** \brief DETECTOR class + * + */ +class DescriptorLUCID : public DescriptorBase { + + public: + DescriptorLUCID(); + virtual ~DescriptorLUCID(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 DescriptorLUCID::defineDescriptor(const ParamsBasePtr _params) +{ + DescriptorParamsLUCIDPtr params_ptr = std::static_pointer_cast<DescriptorParamsLUCID>(_params); + + descriptor_ = cv::xfeatures2d::LUCID::create(params_ptr->lucid_kernel, + params_ptr->blur_kernel); +} + + +/* + * brief Create object in factory + */ +inline DescriptorBasePtr DescriptorLUCID::create(const std::string& _unique_name, const ParamsBasePtr _params) +{ + DescriptorLUCIDPtr det_ptr = std::make_shared<DescriptorLUCID>(); + det_ptr->setName(_unique_name); + det_ptr->defineDescriptor(_params); + return det_ptr; +} + +} /* namespace vision_utils */ + +#endif /* _DESCRIPTOR_LUCID_H_ */ diff --git a/src/descriptors/lucid/descriptor_lucid_load_yaml.cpp b/src/descriptors/lucid/descriptor_lucid_load_yaml.cpp new file mode 100644 index 0000000..50de9f1 --- /dev/null +++ b/src/descriptors/lucid/descriptor_lucid_load_yaml.cpp @@ -0,0 +1,46 @@ +#include "descriptor_lucid.h" + +#ifdef USING_YAML + +// yaml-cpp library +#include <yaml-cpp/yaml.h> + +namespace vision_utils +{ + +namespace +{ + +static ParamsBasePtr createParamsLUCIDDescriptor(const std::string & _filename_dot_yaml) +{ + DescriptorParamsLUCIDPtr params_ptr = std::make_shared<DescriptorParamsLUCID>(); + + 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>() == "LUCID") + { + params_ptr->lucid_kernel = d_yaml["lucid_kernel"].as<int>(); + params_ptr->blur_kernel = d_yaml["blur_kernel"].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_desLUCID_params = ParamsFactory::get().registerCreator("LUCID DES", createParamsLUCIDDescriptor); + +} /* namespace [unnamed] */ + +} /* namespace vision_utils */ + +#endif /* IF USING_YAML */ + diff --git a/src/examples/test_descriptor.cpp b/src/examples/test_descriptor.cpp index e408c7a..0d451a8 100644 --- a/src/examples/test_descriptor.cpp +++ b/src/examples/test_descriptor.cpp @@ -32,7 +32,8 @@ #include "../descriptors/freak/descriptor_freak.h" #include "../descriptors/brief/descriptor_brief.h" #include "../descriptors/daisy/descriptor_daisy.h" -//#include "../descriptors/lucid/descriptor_lucid.h" +#include "../descriptors/lucid/descriptor_lucid.h" +//#include "../descriptors/dense/descriptor_dense.h" int main(void) { @@ -110,8 +111,10 @@ int main(void) des_ptr = std::static_pointer_cast<DescriptorBRIEF>(des_ptr); else if (des_name.compare("DAISY") == 0) des_ptr = std::static_pointer_cast<DescriptorDAISY>(des_ptr); -// else if (des_name.compare("LUCID") == 0) -// des_ptr = std::static_pointer_cast<DescriptorLUCID>(des_ptr); + else if (des_name.compare("LUCID") == 0) + des_ptr = std::static_pointer_cast<DescriptorLUCID>(des_ptr); + // else if (des_name.compare("DENSE") == 0) + // des_ptr = std::static_pointer_cast<DescriptorDENSE>(des_ptr); std::cout << std::endl << "... Testing " << det_ptr->getName() << " with " << des_ptr->getName() << " ..." << std::endl; diff --git a/src/examples/yaml/LUCID.yaml b/src/examples/yaml/LUCID.yaml new file mode 100644 index 0000000..6889d08 --- /dev/null +++ b/src/examples/yaml/LUCID.yaml @@ -0,0 +1,6 @@ +sensor: + type: "USB_CAM" +descriptor: + type: "LUCID" + lucid_kernel: 1 + blur_kernel: 2 \ No newline at end of file -- GitLab