From 59c9b65d9de09fc75eecf34cbd0086025bba0be9 Mon Sep 17 00:00:00 2001 From: asantamaria <asantamaria@iri.upc.edu> Date: Fri, 28 Jul 2017 10:49:17 +0200 Subject: [PATCH] cleaned namespace names --- src/examples/feature_detectors.cpp | 2 +- .../feature_detectors_and_descriptors.cpp | 6 +- src/feature_descriptor/feature_descriptor.cpp | 52 ++--- src/feature_descriptor/feature_descriptor.h | 14 +- src/feature_detector/feature_detector.cpp | 197 +++++++++--------- src/feature_detector/feature_detector.h | 17 +- 6 files changed, 145 insertions(+), 143 deletions(-) diff --git a/src/examples/feature_detectors.cpp b/src/examples/feature_detectors.cpp index de818e0..650dbcf 100644 --- a/src/examples/feature_detectors.cpp +++ b/src/examples/feature_detectors.cpp @@ -8,7 +8,7 @@ int main(int argc, char *argv[]) { CFeature_Detector detector; - std::vector<Detector::Type> detectors_list; + std::vector<detector::Type> detectors_list; detectors_list = detector.listDetectors(); std::cout << "----------------------------------------" << std::endl; diff --git a/src/examples/feature_detectors_and_descriptors.cpp b/src/examples/feature_detectors_and_descriptors.cpp index 3c93703..ca11eb2 100644 --- a/src/examples/feature_detectors_and_descriptors.cpp +++ b/src/examples/feature_detectors_and_descriptors.cpp @@ -8,7 +8,7 @@ int main(int argc, char *argv[]) { CFeature_Detector detector; - std::vector<Detector::Type> detectors_list; + std::vector<detector::Type> detectors_list; detectors_list = detector.listDetectors(); std::cout << "---------------------------------------------------------" << std::endl; @@ -18,7 +18,7 @@ int main(int argc, char *argv[]) for (unsigned int ii=0; ii<detectors_list.size(); ii++) { - if ( (detectors_list[ii]!= Detector::LSD) && (detectors_list[ii] != Detector::ED) ) + if ( (detectors_list[ii]!= detector::LSD) && (detectors_list[ii] != detector::ED) ) std::cout << "[" << ii << "]: " << detectors_list[ii] << std::endl; } @@ -28,7 +28,7 @@ int main(int argc, char *argv[]) detector.setDetectorType(feat_type); CFeature_Descriptor descriptor; - std::vector<Descriptor::Type> descriptor_list; + std::vector<descriptor::Type> descriptor_list; descriptor_list = descriptor.listDescriptors(); for (unsigned int ii=0; ii<descriptor_list.size(); ii++) diff --git a/src/feature_descriptor/feature_descriptor.cpp b/src/feature_descriptor/feature_descriptor.cpp index 61855e6..4ef6c37 100644 --- a/src/feature_descriptor/feature_descriptor.cpp +++ b/src/feature_descriptor/feature_descriptor.cpp @@ -1,7 +1,7 @@ #include "feature_descriptor.h" -CFeature_Descriptor::CFeature_Descriptor(const Descriptor::Type& _type) : - type_(Descriptor::__DELIM__), is_init_(false), descript_time_(0.0) { +CFeature_Descriptor::CFeature_Descriptor(const descriptor::Type& _type) : + type_(descriptor::__DELIM__), is_init_(false), descript_time_(0.0) { is_init_ = init(_type); @@ -13,7 +13,7 @@ CFeature_Descriptor::CFeature_Descriptor(const Descriptor::Type& _type) : } CFeature_Descriptor::CFeature_Descriptor(const int&_type) : - type_(Descriptor::__DELIM__), is_init_(false), descript_time_(0.0) { + type_(descriptor::__DELIM__), is_init_(false), descript_time_(0.0) { is_init_ = init(intToDescriptorType(_type)); @@ -25,25 +25,25 @@ CFeature_Descriptor::CFeature_Descriptor(const int&_type) : } CFeature_Descriptor::CFeature_Descriptor() : - type_(Descriptor::__DELIM__), is_init_(false), descript_time_(0.0) { + type_(descriptor::__DELIM__), is_init_(false), descript_time_(0.0) { } CFeature_Descriptor::~CFeature_Descriptor() { } -std::vector<Descriptor::Type> CFeature_Descriptor::listDescriptors(void) +std::vector<descriptor::Type> CFeature_Descriptor::listDescriptors(void) { - std::vector<Descriptor::Type> list; + std::vector<descriptor::Type> list; - for (int ii = 0; ii < Descriptor::LUCID + 1; ii++) + for (int ii = 0; ii < descriptor::__DELIM__; ii++) { - list.push_back(static_cast<Descriptor::Type>(ii)); + list.push_back(static_cast<descriptor::Type>(ii)); } return list; } -bool CFeature_Descriptor::setDescriptorType(const Descriptor::Type& _type) +bool CFeature_Descriptor::setDescriptorType(const descriptor::Type& _type) { is_init_ = init(_type); return is_init_; @@ -60,7 +60,7 @@ double CFeature_Descriptor::getDescriptorTime(void) return descript_time_; } -bool CFeature_Descriptor::init(Descriptor::Type _type) { +bool CFeature_Descriptor::init(descriptor::Type _type) { if (is_init_) std::cerr << "[CFeature_Descriptor::init]: Descriptor already initialized." @@ -70,51 +70,51 @@ bool CFeature_Descriptor::init(Descriptor::Type _type) { // TODO: Set parameters for each descriptor type switch (_type) { - case Descriptor::ORB: + case descriptor::ORB: feature_descriptor_ = cv::ORB::create(); success = true; break; - case Descriptor::SIFT: + case descriptor::SIFT: feature_descriptor_ = cv::xfeatures2d::SIFT::create(); success = true; break; - case Descriptor::SURF: + case descriptor::SURF: feature_descriptor_ = cv::xfeatures2d::SURF::create(); success = true; break; - case Descriptor::KAZE: + case descriptor::KAZE: feature_descriptor_ = cv::KAZE::create(); success = true; break; - case Descriptor::AKAZE: + case descriptor::AKAZE: feature_descriptor_ = cv::AKAZE::create(); success = true; break; - case Descriptor::BRISK: + case descriptor::BRISK: feature_descriptor_ = cv::BRISK::create(); success = true; break; - case Descriptor::LATCH: + case descriptor::LATCH: feature_descriptor_ = cv::xfeatures2d::LATCH::create(); success = true; break; - case Descriptor::FREAK: + case descriptor::FREAK: feature_descriptor_ = cv::xfeatures2d::FREAK::create(); success = true; break; - case Descriptor::BRIEF: + case descriptor::BRIEF: feature_descriptor_ = cv::xfeatures2d::BriefDescriptorExtractor::create(); success = true; break; - case Descriptor::DAISY: + case descriptor::DAISY: feature_descriptor_ = cv::xfeatures2d::DAISY::create(); success = true; break; - case Descriptor::LUCID: + case descriptor::LUCID: feature_descriptor_ = cv::xfeatures2d::LUCID::create(1,2); success = true; break; - case Descriptor::__DELIM__: + case descriptor::__DELIM__: success = false; break; } @@ -142,13 +142,13 @@ cv::Mat CFeature_Descriptor::getDescriptor(const cv::Mat& _image, CFeature_Descr return descriptors; } -Descriptor::Type CFeature_Descriptor::intToDescriptorType( +descriptor::Type CFeature_Descriptor::intToDescriptorType( const unsigned int _i) { - Descriptor::Type type; + descriptor::Type type; - for (unsigned int ii = 0; ii < Descriptor::__DELIM__; ii++) { + for (unsigned int ii = 0; ii < descriptor::__DELIM__; ii++) { if (ii == _i) - type = static_cast<Descriptor::Type>(ii); + type = static_cast<descriptor::Type>(ii); } return type; diff --git a/src/feature_descriptor/feature_descriptor.h b/src/feature_descriptor/feature_descriptor.h index df5dbbe..0a88c02 100644 --- a/src/feature_descriptor/feature_descriptor.h +++ b/src/feature_descriptor/feature_descriptor.h @@ -15,7 +15,7 @@ typedef cv::Ptr<cv::DescriptorExtractor> FeatureDescriptorPtr; -namespace Descriptor { +namespace descriptor { /** * \brief MACROS to generate all detector types and their corresponding strings @@ -59,7 +59,7 @@ public: typedef std::vector<cv::KeyPoint> KeyPointVector; //CFeature_Descriptor(const DESCRIPTOR_TYPE& _type); - CFeature_Descriptor(const Descriptor::Type& _type); + CFeature_Descriptor(const descriptor::Type& _type); CFeature_Descriptor(const int&_type); CFeature_Descriptor(void); @@ -68,12 +68,12 @@ public: /** * \brief List the defined detector types */ - std::vector<Descriptor::Type> listDescriptors(void); + std::vector<descriptor::Type> listDescriptors(void); /** * \brief Set descriptor type */ - bool setDescriptorType(const Descriptor::Type& _type); + bool setDescriptorType(const descriptor::Type& _type); bool setDescriptorType(const int& _type); /** @@ -89,7 +89,7 @@ public: private: - Descriptor::Type type_; + descriptor::Type type_; // Flags bool is_init_; @@ -101,14 +101,14 @@ private: /** * \brief Initialize descriptor */ - bool init(Descriptor::Type _type); + bool init(descriptor::Type _type); /** * \brief Convert an integer to its corresponding descriptor flag. * * By default return ORB. */ - Descriptor::Type intToDescriptorType(const unsigned int _i); + descriptor::Type intToDescriptorType(const unsigned int _i); }; diff --git a/src/feature_detector/feature_detector.cpp b/src/feature_detector/feature_detector.cpp index 695f6b5..e20a67e 100644 --- a/src/feature_detector/feature_detector.cpp +++ b/src/feature_detector/feature_detector.cpp @@ -1,7 +1,7 @@ #include "feature_detector.h" -CFeature_Detector::CFeature_Detector(const Detector::Type& _type) : - type_(Detector::__DELIM__), is_init_(false), is_line_(false), is_limited_(false), keypoints_limit_(-1), detect_time_(0.0) +CFeature_Detector::CFeature_Detector(const detector::Type& _type) : + type_(detector::__DELIM__), is_init_(false), is_line_(false), is_limited_(false), keypoints_limit_(-1), detect_time_(0.0) { is_init_ = init(_type); @@ -13,9 +13,10 @@ CFeature_Detector::CFeature_Detector(const Detector::Type& _type) : } CFeature_Detector::CFeature_Detector(const int&_type) : - type_(Detector::__DELIM__), is_init_(false), is_line_(false), is_limited_(false), keypoints_limit_(-1), detect_time_(0.0) + type_(detector::__DELIM__), is_init_(false), is_line_(false), is_limited_(false), keypoints_limit_(-1), detect_time_(0.0) { - is_init_ = init(intToDetectorType(_type)); + intToType(_type,type_); + is_init_ = init(type_); if (!is_init_) { @@ -25,7 +26,7 @@ CFeature_Detector::CFeature_Detector(const int&_type) : } CFeature_Detector::CFeature_Detector(void) : - type_(Detector::__DELIM__), is_init_(false), is_line_(false), is_limited_(false), keypoints_limit_(-1), detect_time_(0.0) + type_(detector::__DELIM__), is_init_(false), is_line_(false), is_limited_(false), keypoints_limit_(-1), detect_time_(0.0) { } @@ -33,19 +34,19 @@ CFeature_Detector::~CFeature_Detector() { } -std::vector<Detector::Type> CFeature_Detector::listDetectors(void) +std::vector<detector::Type> CFeature_Detector::listDetectors(void) { - std::vector<Detector::Type> list; + std::vector<detector::Type> list; - for (int ii = 0; ii < Detector::ED + 1; ii++) + for (int ii = 0; ii < detector::__DELIM__; ii++) { - list.push_back(static_cast<Detector::Type>(ii)); + list.push_back(static_cast<detector::Type>(ii)); } return list; } -bool CFeature_Detector::setDetectorType(const Detector::Type& _type) +bool CFeature_Detector::setDetectorType(const detector::Type& _type) { is_init_ = init(_type); return is_init_; @@ -53,7 +54,9 @@ bool CFeature_Detector::setDetectorType(const Detector::Type& _type) bool CFeature_Detector::setDetectorType(const int& _type) { - is_init_ = init(intToDetectorType(_type)); + detector::Type type; + intToType(_type, type); + is_init_ = init(type); return is_init_; } @@ -77,87 +80,6 @@ int CFeature_Detector::getKeyPointsLimit(void) return keypoints_limit_; } -bool CFeature_Detector::init(Detector::Type _type) -{ - if (is_init_) - std::cerr << "[CFeature_Detector::init]: Detector already initialized." << std::endl; - - bool success = false; - - // TODO: Set parameters for each detector type - switch (_type) - { - case Detector::FAST: - feature_detector_ = cv::FastFeatureDetector::create(); - success = true; - break; - case Detector::SIFT: - feature_detector_ = cv::xfeatures2d::SIFT::create(); - success = true; - break; - case Detector::SURF: - feature_detector_ = cv::xfeatures2d::SURF::create(); - success = true; - break; - case Detector::ORB: - feature_detector_ = cv::ORB::create(); - success = true; - break; - case Detector::BRISK: - feature_detector_ = cv::BRISK::create(); - success = true; - break; - case Detector::MSER: - feature_detector_ = cv::MSER::create(); - success = true; - break; - case Detector::GFTT: - feature_detector_ = cv::GFTTDetector::create(1000, 0.01, 1.0, 3, false, 0.04); - success = true; - break; - case Detector::HARRIS: - feature_detector_ = cv::GFTTDetector::create(1000, 0.01, 1.0, 3, true, 0.04); - success = true; - break; - case Detector::SBD: - feature_detector_ = cv::SimpleBlobDetector::create(); - success = true; - break; - case Detector::KAZE: - feature_detector_ = cv::KAZE::create(); - success = true; - break; - case Detector::AKAZE: - feature_detector_ = cv::AKAZE::create(); - success = true; - break; - case Detector::AGAST: - feature_detector_ = cv::AgastFeatureDetector::create(); - success = true; - break; - case Detector::LSD: - lsd_detector_ = cv::line_descriptor::LSDDetector::createLSDDetector(); - is_line_ = true; - success = true; - break; - case Detector::ED: - ed_detector_ = cv::line_descriptor::BinaryDescriptor::createBinaryDescriptor(); - is_line_ = true; - success = true; - break; - case Detector::__DELIM__: - success = false; - break; - } - - if (success) - type_ = _type; - else - std::cerr << "[Feature Detector]: detector_type " << _type << " doesn't exist !" << std::endl; - - return success; -} - CFeature_Detector::KeyPointVector CFeature_Detector::detectKeyPoints(const cv::Mat& _image) { if (!is_init_) @@ -195,7 +117,7 @@ CFeature_Detector::KeyLineVector CFeature_Detector::detectKeyLines(const cv::Mat mask_ = cv::Mat::ones(_image.size(), CV_8U); clock_t tStart = clock(); - if (type_ == Detector::LSD) + if (type_ == detector::LSD) lsd_detector_->detect(_image, kls, SCALE_FACTOR_LINE_DETECTOR, NUM_OCTAVE_LINE_DETECTOR, mask_); else ed_detector_->detect(_image, kls2, mask_); @@ -236,15 +158,92 @@ cv::Mat CFeature_Detector::drawKeyFeatures(const cv::Mat& _image, const KeyLineV return img_out; } -Detector::Type CFeature_Detector::intToDetectorType(const unsigned int _i) +void CFeature_Detector::intToType(const unsigned int _i, detector::Type& _type) { - Detector::Type type; - - for (unsigned int ii = 0; ii < Detector::__DELIM__; ii++) + for (unsigned int ii = 0; ii < detector::__DELIM__; ii++) { if (ii == _i) - type = static_cast<Detector::Type>(ii); + _type = static_cast<detector::Type>(ii); } +} - return type; +bool CFeature_Detector::init(detector::Type _type) +{ + if (is_init_) + std::cerr << "[CFeature_Detector::init]: Detector already initialized." << std::endl; + + bool success = false; + + // TODO: Set parameters for each detector type + switch (_type) + { + case detector::FAST: + feature_detector_ = cv::FastFeatureDetector::create(); + success = true; + break; + case detector::SIFT: + feature_detector_ = cv::xfeatures2d::SIFT::create(); + success = true; + break; + case detector::SURF: + feature_detector_ = cv::xfeatures2d::SURF::create(); + success = true; + break; + case detector::ORB: + feature_detector_ = cv::ORB::create(); + success = true; + break; + case detector::BRISK: + feature_detector_ = cv::BRISK::create(); + success = true; + break; + case detector::MSER: + feature_detector_ = cv::MSER::create(); + success = true; + break; + case detector::GFTT: + feature_detector_ = cv::GFTTDetector::create(1000, 0.01, 1.0, 3, false, 0.04); + success = true; + break; + case detector::HARRIS: + feature_detector_ = cv::GFTTDetector::create(1000, 0.01, 1.0, 3, true, 0.04); + success = true; + break; + case detector::SBD: + feature_detector_ = cv::SimpleBlobDetector::create(); + success = true; + break; + case detector::KAZE: + feature_detector_ = cv::KAZE::create(); + success = true; + break; + case detector::AKAZE: + feature_detector_ = cv::AKAZE::create(); + success = true; + break; + case detector::AGAST: + feature_detector_ = cv::AgastFeatureDetector::create(); + success = true; + break; + case detector::LSD: + lsd_detector_ = cv::line_descriptor::LSDDetector::createLSDDetector(); + is_line_ = true; + success = true; + break; + case detector::ED: + ed_detector_ = cv::line_descriptor::BinaryDescriptor::createBinaryDescriptor(); + is_line_ = true; + success = true; + break; + case detector::__DELIM__: + success = false; + break; + } + + if (success) + type_ = _type; + else + std::cerr << "[Feature Detector]: detector_type " << _type << " doesn't exist !" << std::endl; + + return success; } diff --git a/src/feature_detector/feature_detector.h b/src/feature_detector/feature_detector.h index 9fc148a..7c07945 100644 --- a/src/feature_detector/feature_detector.h +++ b/src/feature_detector/feature_detector.h @@ -3,6 +3,9 @@ #include <time.h> +// Own stuff +#include "vision_utils.h" + // OpenCV stuff #include <opencv2/core/core.hpp> #include <opencv2/core/types.hpp> @@ -19,7 +22,7 @@ typedef cv::Ptr<cv::FeatureDetector> FeatureDetectorPtr; typedef cv::Ptr<cv::line_descriptor::LSDDetector> LSDDetector; typedef cv::Ptr<cv::line_descriptor::BinaryDescriptor> EDDetector; -namespace Detector +namespace detector { /** @@ -74,7 +77,7 @@ class CFeature_Detector /** * \brief Constructor */ - CFeature_Detector(const Detector::Type& _type); + CFeature_Detector(const detector::Type& _type); CFeature_Detector(const int& _type); CFeature_Detector(void); @@ -86,12 +89,12 @@ class CFeature_Detector /** * \brief List the defined detector types */ - std::vector<Detector::Type> listDetectors(void); + std::vector<detector::Type> listDetectors(void); /** * \brief Set detector type */ - bool setDetectorType(const Detector::Type& _type); + bool setDetectorType(const detector::Type& _type); bool setDetectorType(const int& _type); /** @@ -133,7 +136,7 @@ class CFeature_Detector private: - Detector::Type type_; + detector::Type type_; // Flags bool is_init_; @@ -153,14 +156,14 @@ class CFeature_Detector /** * \brief Initialize detector */ - bool init(Detector::Type _type); + bool init(detector::Type _type); /** * \brief Convert an integer to its corresponding detector flag. * * By default return ORB. */ - Detector::Type intToDetectorType(const unsigned int _i); + void intToType(const unsigned int _i, detector::Type& _type); }; -- GitLab