diff --git a/.settings/language.settings.xml b/.settings/language.settings.xml index 5c600911b1171a0f9b6c2e8b05326e3a3daa9ed9..c588c28637ad0e14480e5c2ed2309f04e8e12931 100644 --- a/.settings/language.settings.xml +++ b/.settings/language.settings.xml @@ -5,7 +5,7 @@ <provider copy-of="extension" id="org.eclipse.cdt.ui.UserLanguageSettingsProvider"/> <provider-reference id="org.eclipse.cdt.core.ReferencedProjectsLanguageSettingsProvider" ref="shared-provider"/> <provider copy-of="extension" id="org.eclipse.cdt.managedbuilder.core.GCCBuildCommandParser"/> - <provider class="org.eclipse.cdt.managedbuilder.language.settings.providers.GCCBuiltinSpecsDetector" console="false" env-hash="1504749124108071272" id="org.eclipse.cdt.managedbuilder.core.GCCBuiltinSpecsDetector" keep-relative-paths="false" name="CDT GCC Built-in Compiler Settings" parameter="${COMMAND} ${FLAGS} -E -P -v -dD "${INPUTS}"" prefer-non-shared="true"> + <provider class="org.eclipse.cdt.managedbuilder.language.settings.providers.GCCBuiltinSpecsDetector" console="false" env-hash="1476617952823822664" id="org.eclipse.cdt.managedbuilder.core.GCCBuiltinSpecsDetector" keep-relative-paths="false" name="CDT GCC Built-in Compiler Settings" parameter="${COMMAND} ${FLAGS} -E -P -v -dD "${INPUTS}"" prefer-non-shared="true"> <language-scope id="org.eclipse.cdt.core.gcc"/> <language-scope id="org.eclipse.cdt.core.g++"/> </provider> diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index fe494bf234b90dc2d9490a3f08a93a4263b042f4..e29cb8d122877d06078a02ec65a39c8d511866ca 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,5 +1,5 @@ # library source files -SET(sources vision_utils.cpp vu_base/vu_base.cpp cam_utils/cam_utils.cpp feature_detector/feature_detector.cpp feature_descriptor/feature_descriptor.cpp feature_matcher/feature_matcher.cpp) +SET(sources vision_utils.cpp cam_utils/cam_utils.cpp feature_detector/feature_detector.cpp feature_descriptor/feature_descriptor.cpp feature_matcher/feature_matcher.cpp) # application header files SET(headers vision_utils.h vu_base/vu_base.h cam_utils/cam_utils.h feature_detector/feature_detector.h feature_descriptor/feature_descriptor.h feature_matcher/feature_matcher.h) diff --git a/src/examples/CMakeLists.txt b/src/examples/CMakeLists.txt index 35b3b32efa94e77a97654e4a327fd8d3b2cea9c4..699b1161afd320eae55fc39dbaf66d540abffabb 100644 --- a/src/examples/CMakeLists.txt +++ b/src/examples/CMakeLists.txt @@ -1,9 +1,11 @@ # create an example application ADD_EXECUTABLE(capture capture.cpp) -ADD_EXECUTABLE(feature_detectors feature_detectors.cpp) -ADD_EXECUTABLE(feature_detectors_and_descriptors feature_detectors_and_descriptors.cpp) +ADD_EXECUTABLE(feature_detectors feature_detect.cpp) +ADD_EXECUTABLE(feature_detectors_and_descriptors feature_detect_descript.cpp) +ADD_EXECUTABLE(feature_detectors_descriptors_and_matchers feature_detect_descript_match.cpp) # link necessary libraries TARGET_LINK_LIBRARIES(capture vision_utils) TARGET_LINK_LIBRARIES(feature_detectors vision_utils) -TARGET_LINK_LIBRARIES(feature_detectors_and_descriptors vision_utils) \ No newline at end of file +TARGET_LINK_LIBRARIES(feature_detectors_and_descriptors vision_utils) +TARGET_LINK_LIBRARIES(feature_detectors_descriptors_and_matchers vision_utils) \ No newline at end of file diff --git a/src/examples/capture.cpp b/src/examples/capture.cpp index 72e9af778dce0d131b7f2b9d17463bbbaacac6af..ce2601496a3683ebba4f8f2ee9ebea07f39a0549 100644 --- a/src/examples/capture.cpp +++ b/src/examples/capture.cpp @@ -1,7 +1,7 @@ // OWN stuff #include <string> -#include "../vision_utils.h" +#include <vision_utils.h> int main(int argc, char *argv[]) { diff --git a/src/examples/feature_detectors.cpp b/src/examples/feature_detect.cpp similarity index 91% rename from src/examples/feature_detectors.cpp rename to src/examples/feature_detect.cpp index 14bf3b2ede694430eae1e98ab9ff336040caae10..b07669991a7c2d6abec5d6e333cb65d2a4c5616e 100644 --- a/src/examples/feature_detectors.cpp +++ b/src/examples/feature_detect.cpp @@ -1,31 +1,29 @@ // OWN stuff #include <string> -#include "../vision_utils.h" +#include "vision_utils.h" int main(int argc, char *argv[]) { - CFeature_Detector detector; - CDetector_Params detector_params; - -// std::vector<detector::Type> detectors_list; - std::vector<std::string> detectors_list; - detectors_list = detector.list(); - std::cout << "----------------------------------------" << std::endl; std::cout << "| Feature detector example |" << std::endl; std::cout << "----------------------------------------" << std::endl; std::cout << std::endl; + CFeature_Detector detector; + CDetector_Params detector_params; // TODO: Fill parameters + + std::vector<std::string> detectors_list; + detectors_list = detector.list(); + for (unsigned int ii=0; ii<detectors_list.size(); ii++) std::cout << "[" << ii << "]: " << detectors_list[ii] << std::endl; std::cout << std::endl << "Which DETECTOR do you want to test?: "; int feat_type; std::cin >> feat_type; -// detector.setType(feat_type); - detector.set(feat_type,detector_params); + detector.set(detectors_list[feat_type],detector_params); std::cout << std::endl << "Testing: " << detectors_list[feat_type] << std::endl; // Open camera diff --git a/src/examples/feature_detect_descript.cpp b/src/examples/feature_detect_descript.cpp new file mode 100644 index 0000000000000000000000000000000000000000..1ff580f46f57cea8075dd77c84be0997db13485e --- /dev/null +++ b/src/examples/feature_detect_descript.cpp @@ -0,0 +1,95 @@ +// OWN stuff +#include <string> + +#include "vision_utils.h" + + +int main(int argc, char *argv[]) +{ + std::cout << "---------------------------------------------------------" << std::endl; + std::cout << "| Feature detectors and descriptors example |" << std::endl; + std::cout << "---------------------------------------------------------" << std::endl; + std::cout << std::endl; + + CFeature_Detector detector; + CDetector_Params detector_params; // TODO: Fill parameters + + std::vector<std::string> detectors_list; + detectors_list = detector.list(); + + for (unsigned int ii=0; ii<detectors_list.size(); ii++) + { + if ( (detectors_list[ii].compare("LSD")!=0) && (detectors_list[ii].compare("ED")!=0) ) + std::cout << "[" << ii << "]: " << detectors_list[ii] << std::endl; + } + + std::cout << std::endl << "Which DETECTOR do you want to test?: "; + int feat_type; + std::cin >> feat_type; + detector.set(detectors_list[feat_type],detector_params); + std::cout << std::endl << "Testing: " << detectors_list[feat_type] << std::endl; + + CFeature_Descriptor descriptor; + CDescriptor_Params descriptor_params; // TODO: Fill parameters + + std::vector<std::string> descriptor_list; + descriptor_list = descriptor.list(); + + for (unsigned int ii=0; ii<descriptor_list.size(); ii++) + std::cout << "[" << ii << "]: " << descriptor_list[ii] << std::endl; + + std::cout << std::endl << "Which DESCRIPTOR do you want to test?: "; + int desc_type; + std::cin >> desc_type; + descriptor.set(descriptor_list[desc_type],descriptor_params); + std::cout << std::endl << "Testing: " << detectors_list[feat_type] << " + " << descriptor_list[desc_type] << " (DETECTOR + DESCRIPTOR)" << std::endl; + + // Open camera + cv::VideoCapture cam; + CCamUtils cam_fc; + cam_fc.openCamera(0, cam); + + // Create displays + cv::startWindowThread(); + cv::namedWindow("Original image", cv::WINDOW_NORMAL); + cv::namedWindow("Detections", cv::WINDOW_NORMAL); + + // The following line is used to remove the OpenCV "init done" from the terminal + std::cout << "\e[A" << " " << std::endl; + + for (int nframe = 0; nframe < 1000; ++nframe) + { + // Get frame + cv::Mat frame; + cam_fc.getFrame(cam, frame); + + // Show ORIGINAL frame + cv::imshow("Original image", frame); + + // Detector + CFeature_Detector::KeyPointVector keypoints; + keypoints = detector.detectKeyPoints(frame); + + // Descriptor + cv::Mat descriptors; + descriptors = descriptor.getDescriptor(frame,keypoints); + + // Show frame with features + detector.drawKeyFeatures(frame, keypoints); + + std::cout << "\e[A" << + "Detection time: " << detector.getTime() << " " << + "Description time: " << descriptor.getTime() << " " << + "TOTAL time: " << detector.getTime() + descriptor.getTime() << std::endl; + + // Show NEW frame + cv::imshow("Detections", frame); + cv::waitKey(1); + // if (cv::waitKey(30) >= 0) break; + } + + cv::destroyAllWindows(); +} + + + diff --git a/src/examples/feature_detect_descript_match.cpp b/src/examples/feature_detect_descript_match.cpp new file mode 100644 index 0000000000000000000000000000000000000000..dc076db4a3082b36c78dee7995c097809772b164 --- /dev/null +++ b/src/examples/feature_detect_descript_match.cpp @@ -0,0 +1,116 @@ +// OWN stuff +#include <string> + +#include "vision_utils.h" + + +int main(int argc, char *argv[]) +{ + std::cout << "-------------------------------------------------------------------" << std::endl; + std::cout << "| Feature detectors, descriptors and matchers example |" << std::endl; + std::cout << "-------------------------------------------------------------------" << std::endl; + std::cout << std::endl; + + CFeature_Detector detector; + CDetector_Params detector_params; // TODO: Fill parameters + + std::vector<std::string> detectors_list; + detectors_list = detector.list(); + + for (unsigned int ii=0; ii<detectors_list.size(); ii++) + { + if ( (detectors_list[ii].compare("LSD")!=0) && (detectors_list[ii].compare("ED")!=0) ) + std::cout << "[" << ii << "]: " << detectors_list[ii] << std::endl; + } + + std::cout << std::endl << "Which DETECTOR do you want to test?: "; + int feat_type; + std::cin >> feat_type; + detector.set(detectors_list[feat_type],detector_params); + + CFeature_Descriptor descriptor; + CDescriptor_Params descriptor_params; // TODO: Fill parameters + + std::vector<std::string> descriptor_list; + descriptor_list = descriptor.list(); + + for (unsigned int ii=0; ii<descriptor_list.size(); ii++) + std::cout << "[" << ii << "]: " << descriptor_list[ii] << std::endl; + + std::cout << std::endl << "Which DESCRIPTOR do you want to test?: "; + int desc_type; + std::cin >> desc_type; + descriptor.set(descriptor_list[desc_type],descriptor_params); + + CFeature_Matcher matcher; + CMatcher_Params matcher_params; // TODO: Fill parameters + + std::vector<std::string> matchers_list; + matchers_list = matcher.list(); + + for (unsigned int ii=0; ii<matchers_list.size(); ii++) + std::cout << "[" << ii << "]: " << matchers_list[ii] << std::endl; + + std::cout << std::endl << "Which MATCHER do you want to test?: "; + int match_type; + std::cin >> match_type; + matcher.set(matchers_list[match_type],matcher_params); + + std::cout << std::endl << "Testing: " << detectors_list[feat_type] << " + " << descriptor_list[desc_type] << " + " << matchers_list[match_type] << " (DETECTOR + DESCRIPTOR + MATCHER)" << std::endl; + + // Open camera + cv::VideoCapture cam; + CCamUtils cam_fc; + cam_fc.openCamera(0, cam); + + // Create displays + cv::startWindowThread(); + cv::namedWindow("Original image", cv::WINDOW_NORMAL); + cv::namedWindow("Detections", cv::WINDOW_NORMAL); + + // The following line is used to remove the OpenCV "init done" from the terminal + std::cout << "\e[A" << " " << std::endl; + + for (int nframe = 0; nframe < 1000; ++nframe) + { + // Get frame + cv::Mat frame; + cam_fc.getFrame(cam, frame); + + // Show ORIGINAL frame + cv::imshow("Original image", frame); + + // Detector + CFeature_Detector::KeyPointVector keypoints; + keypoints = detector.detectKeyPoints(frame); + + // Descriptor + cv::Mat descriptors; + descriptors = descriptor.getDescriptor(frame,keypoints); + + // TODO: Implement matcher +// if (nframe > 0) +// { +// cv::Mat matchs; +// matchs = matcher.match(); +// } + + // Show frame with features + detector.drawKeyFeatures(frame, keypoints); + + std::cout << "\e[A" << + "Detection time: " << detector.getTime() << " " << + "Description time: " << descriptor.getTime() << " " << + "TOTAL time: " << detector.getTime() + descriptor.getTime() << std::endl; + + // Show NEW frame + cv::imshow("Detections", frame); + cv::waitKey(1); + // if (cv::waitKey(30) >= 0) break; + } + + cv::destroyAllWindows(); +} + + + diff --git a/src/examples/feature_detectors_and_descriptors.cpp b/src/examples/feature_detectors_and_descriptors.cpp deleted file mode 100644 index 56db99b1032a8921f08e85af39f637d3e27bb135..0000000000000000000000000000000000000000 --- a/src/examples/feature_detectors_and_descriptors.cpp +++ /dev/null @@ -1,90 +0,0 @@ -// OWN stuff -#include <string> - -#include "../vision_utils.h" - - -int main(int argc, char *argv[]) -{ -// CFeature_Detector detector; -// std::vector<detector::Type> detectors_list; -// detectors_list = detector.list(); -// -// std::cout << "---------------------------------------------------------" << std::endl; -// std::cout << "| Feature detectors and descriptors example |" << std::endl; -// std::cout << "---------------------------------------------------------" << std::endl; -// std::cout << std::endl; -// -// for (unsigned int ii=0; ii<detectors_list.size(); ii++) -// { -// if ( (detectors_list[ii]!= detector::LSD) && (detectors_list[ii] != detector::ED) ) -// std::cout << "[" << ii << "]: " << detectors_list[ii] << std::endl; -// } -// -// std::cout << std::endl << "Which DETECTOR do you want to test?: "; -// int feat_type; -// std::cin >> feat_type; -// detector.setType(feat_type); -// -// CFeature_Descriptor descriptor; -// std::vector<descriptor::Type> descriptor_list; -// descriptor_list = descriptor.list(); -// -// for (unsigned int ii=0; ii<descriptor_list.size(); ii++) -// std::cout << "[" << ii << "]: " << descriptor_list[ii] << std::endl; -// -// std::cout << std::endl << "Which DESCRIPTOR do you want to test?: "; -// int desc_type; -// std::cin >> desc_type; -// descriptor.setType(desc_type); -// std::cout << std::endl << "Testing: " << detectors_list[feat_type] << " + " << descriptor_list[feat_type] << " (DETECTOR + DESCRIPTOR)" << std::endl; -// -// // Open camera -// cv::VideoCapture cam; -// CCamUtils cam_fc; -// cam_fc.openCamera(0, cam); -// -// // Create displays -// cv::startWindowThread(); -// cv::namedWindow("Original image", cv::WINDOW_NORMAL); -// cv::namedWindow("Detections", cv::WINDOW_NORMAL); -// -// // The following line is used to remove the OpenCV "init done" from the terminal -// std::cout << "\e[A" << " " << std::endl; -// -// for (int nframe = 0; nframe < 1000; ++nframe) -// { -// // Get frame -// cv::Mat frame; -// cam_fc.getFrame(cam, frame); -// -// // Show ORIGINAL frame -// cv::imshow("Original image", frame); -// -// // Detector -// CFeature_Detector::KeyPointVector keypoints; -// keypoints = detector.detectKeyPoints(frame); -// -// // Descriptor -// cv::Mat descriptors; -// descriptors = descriptor.getDescriptor(frame,keypoints); -// -// // Show frame with features -// detector.drawKeyFeatures(frame, keypoints); -// -// std::cout << "\e[A" << -// "Detection time: " << detector.getTime() << " " << -// "Description time: " << descriptor.getTime() << " " << -// "TOTAL time: " << detector.getTime() + descriptor.getTime() << std::endl; -// -// // Show NEW frame -// cv::imshow("Detections", frame); -// cv::waitKey(1); -// // if (cv::waitKey(30) >= 0) break; -// } -// -// cv::destroyAllWindows(); -} - - - diff --git a/src/feature_descriptor/feature_descriptor.cpp b/src/feature_descriptor/feature_descriptor.cpp index 2ae1a3124091833c6439776f655214f45ac8312a..552bd02be6ed70c34fdd8ba4c957a98cb2e38970 100644 --- a/src/feature_descriptor/feature_descriptor.cpp +++ b/src/feature_descriptor/feature_descriptor.cpp @@ -1,129 +1,107 @@ #include "feature_descriptor.h" -CFeature_Descriptor::CFeature_Descriptor(const descriptor::Type& _type) : - type_(descriptor::__DELIM__) +CFeature_Descriptor::CFeature_Descriptor(const std::string& _type, const CDescriptor_Params& _params) { + setAllTypes(); - is_init_ = init(_type); + is_init_ = init(_type, _params); - if (!is_init_) { + if (!is_init_) + { std::cerr << "[Feature Descriptor]: Something went wrong during initialization! Feature Descriptor not initialized." << std::endl; } } -CFeature_Descriptor::CFeature_Descriptor(const int&_type) : - type_(descriptor::__DELIM__) -{ - - is_init_ = init(intToType(_type)); - - if (!is_init_) { - std::cerr - << "[Feature Descriptor]: Something went wrong during initialization! Feature Descriptor not initialized." - << std::endl; - } -} - -CFeature_Descriptor::CFeature_Descriptor() : - type_(descriptor::__DELIM__) +CFeature_Descriptor::CFeature_Descriptor() { + setAllTypes(); } CFeature_Descriptor::~CFeature_Descriptor() { } -std::vector<descriptor::Type> CFeature_Descriptor::list(void) -{ - std::vector<descriptor::Type> list; - - for (int ii = 0; ii < descriptor::__DELIM__; ii++) - { - list.push_back(static_cast<descriptor::Type>(ii)); - } - - return list; -} - -bool CFeature_Descriptor::setType(const descriptor::Type& _type) +void CFeature_Descriptor::setAllTypes(void) { - is_init_ = init(_type); - return is_init_; + // Define all types + std::vector<std::string> types; + types += "ORB", "SIFT", "SURF", "KAZE", "AKAZE", "BRISK", "LATCH", "FREAK", "BRIEF", "DAISY", "LUCID"; + types_.set(types); } -bool CFeature_Descriptor::setType(const int& _type) +bool CFeature_Descriptor::init(const std::string& _type, const CDescriptor_Params& _params) { - is_init_ = init(intToType(_type)); - return is_init_; -} - -bool CFeature_Descriptor::init(descriptor::Type _type) { - if (is_init_) - std::cerr - << "[CFeature_Descriptor::init]: Descriptor already initialized." - << std::endl; - - bool success = false; - - // TODO: Set parameters for each descriptor type - switch (_type) { - case descriptor::ORB: - feature_descriptor_ = cv::ORB::create(); - success = true; - break; - case descriptor::SIFT: - feature_descriptor_ = cv::xfeatures2d::SIFT::create(); - success = true; - break; - case descriptor::SURF: - feature_descriptor_ = cv::xfeatures2d::SURF::create(); - success = true; - break; - case descriptor::KAZE: - feature_descriptor_ = cv::KAZE::create(); - success = true; - break; - case descriptor::AKAZE: - feature_descriptor_ = cv::AKAZE::create(); - success = true; - break; - case descriptor::BRISK: - feature_descriptor_ = cv::BRISK::create(); - success = true; - break; - case descriptor::LATCH: - feature_descriptor_ = cv::xfeatures2d::LATCH::create(); - success = true; - break; - case descriptor::FREAK: - feature_descriptor_ = cv::xfeatures2d::FREAK::create(); - success = true; - break; - case descriptor::BRIEF: - feature_descriptor_ = cv::xfeatures2d::BriefDescriptorExtractor::create(); - success = true; - break; - case descriptor::DAISY: - feature_descriptor_ = cv::xfeatures2d::DAISY::create(); - success = true; - break; - case descriptor::LUCID: - feature_descriptor_ = cv::xfeatures2d::LUCID::create(1,2); - success = true; - break; - case descriptor::__DELIM__: - success = false; - break; - } + if (is_init_) + { + std::cerr << "[CFeature_Descriptor]: Descriptor already initialized." << std::endl; + return false; + } - if (success) - type_ = _type; - else - std::cerr << "[Feature Descriptor]: descriptor_type " << _type - << " doesn't exist !" << std::endl; + // TODO: Set parameters for each detector type + if (_type.compare(types_(0))==0) + { + feature_descriptor_ = cv::ORB::create(); + type_ = types_(0); + } + else if (_type.compare(types_(1))==0) + { + feature_descriptor_ = cv::xfeatures2d::SIFT::create(); + type_ = types_(1); + } + else if (_type.compare(types_(2))==0) + { + feature_descriptor_ = cv::xfeatures2d::SURF::create(); + type_ = types_(2); + } + else if (_type.compare(types_(3))==0) + { + feature_descriptor_ = cv::KAZE::create(); + type_ = types_(3); + } + else if (_type.compare(types_(4))==0) + { + feature_descriptor_ = cv::AKAZE::create(); + type_ = types_(4); + } + else if (_type.compare(types_(5))==0) + { + feature_descriptor_ = cv::BRISK::create(); + type_ = types_(0); + } + else if (_type.compare(types_(6))==0) + { + feature_descriptor_ = cv::xfeatures2d::LATCH::create(); + type_ = types_(6); + } + else if (_type.compare(types_(7))==0) + { + feature_descriptor_ = cv::xfeatures2d::FREAK::create(); + type_ = types_(7); + } + else if (_type.compare(types_(8))==0) + { + feature_descriptor_ = cv::xfeatures2d::BriefDescriptorExtractor::create(); + type_ = types_(8); + } + else if (_type.compare(types_(9))==0) + { + feature_descriptor_ = cv::xfeatures2d::DAISY::create(); + type_ = types_(9); + } + else if (_type.compare(types_(10))==0) + { + feature_descriptor_ = cv::xfeatures2d::LUCID::create(1,2); + type_ = types_(10); + } + else + { + std::cerr << "[Feature Descriptor]: descriptor type " << _type << " doesn't exist !" << std::endl; + return false; + } - return success; + is_init_ = true; + return true; } cv::Mat CFeature_Descriptor::getDescriptor(const cv::Mat& _image, CFeature_Descriptor::KeyPointVector& _kpts) @@ -139,15 +117,3 @@ cv::Mat CFeature_Descriptor::getDescriptor(const cv::Mat& _image, CFeature_Descr return descriptors; } - -descriptor::Type CFeature_Descriptor::intToType( - const unsigned int _i) { - descriptor::Type type; - - for (unsigned int ii = 0; ii < descriptor::__DELIM__; ii++) { - if (ii == _i) - 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 614b1bbed4827b1e464a77c9bde3c1e5376050bb..829fba91f29bc90f586f4dab377b5d054c816066 100644 --- a/src/feature_descriptor/feature_descriptor.h +++ b/src/feature_descriptor/feature_descriptor.h @@ -3,8 +3,8 @@ #include <time.h> -// own -#include "vu_base/vu_base.h" +// Own +#include <vu_base/vu_base.h> // OpenCV #include <opencv2/core/core.hpp> @@ -18,67 +18,30 @@ typedef cv::Ptr<cv::DescriptorExtractor> FeatureDescriptorPtr; -namespace descriptor { - /** - * \brief MACROS to generate all descriptor types and their corresponding strings + * \brief Feature descriptor parameters class */ -#define FOREACH_DESCRIPTOR(DESCRIPTOR) \ - DESCRIPTOR(ORB) \ - DESCRIPTOR(SIFT) \ - DESCRIPTOR(SURF) \ - DESCRIPTOR(KAZE) \ - DESCRIPTOR(AKAZE) \ - DESCRIPTOR(BRISK) \ - DESCRIPTOR(LATCH) \ - DESCRIPTOR(FREAK) \ - DESCRIPTOR(BRIEF) \ - DESCRIPTOR(DAISY) \ - DESCRIPTOR(LUCID) \ - DESCRIPTOR(__DELIM__) \ - -#define GENERATE_ENUM(ENUM) ENUM, -#define GENERATE_STRING(STRING) #STRING, -enum Type { - FOREACH_DESCRIPTOR(GENERATE_ENUM) +class CDescriptor_Params: public CParams { +public: + CDescriptor_Params(void) { + } + ; + ~CDescriptor_Params(void) { + } + ; }; -static const char *DESCRIPTOR_TYPE_STRING[] = { FOREACH_DESCRIPTOR( - GENERATE_STRING) }; - -/** - * \brief Stream operator for the descriptor flags. - */ -inline std::ostream& operator<<(std::ostream& _os, Type _f) { - _os << DESCRIPTOR_TYPE_STRING[_f]; - return _os; -} -} // end of namespace - -class CFeature_Descriptor: public CVu_Base { +class CFeature_Descriptor: public CVu_Base <CDescriptor_Params>{ public: typedef std::vector<cv::KeyPoint> KeyPointVector; - //CFeature_Descriptor(const DESCRIPTOR_TYPE& _type); - CFeature_Descriptor(const descriptor::Type& _type); - CFeature_Descriptor(const int&_type); + CFeature_Descriptor(const std::string& _type, const CDescriptor_Params& _params); CFeature_Descriptor(void); ~CFeature_Descriptor(void); - /** - * \brief List the defined types - */ - std::vector<descriptor::Type> list(void); - - /** - * \brief Set type - */ - bool setType(const descriptor::Type& _type); - bool setType(const int& _type); - /** * \brief Get descriptors */ @@ -87,22 +50,17 @@ public: private: - descriptor::Type type_; - FeatureDescriptorPtr feature_descriptor_; // Feature point descriptor - /** - * \brief Initialize descriptor - */ - bool init(descriptor::Type _type); + /** + * \brief Set all types + */ + void setAllTypes(void); /** - * \brief Convert an integer to its corresponding descriptor flag. - * - * By default return ORB. + * \brief Initialize descriptor */ - descriptor::Type intToType(const unsigned int _i); - + bool init(const std::string &_type, const CDescriptor_Params &_params); }; #endif diff --git a/src/feature_detector/feature_detector.cpp b/src/feature_detector/feature_detector.cpp index 9353c9cdcf45af42de64ce0d17accb61398ccf0e..4c091bc245b9ba72ca5ff0ef6ee01bb826ec5d6d 100644 --- a/src/feature_detector/feature_detector.cpp +++ b/src/feature_detector/feature_detector.cpp @@ -1,21 +1,11 @@ #include "feature_detector.h" CFeature_Detector::CFeature_Detector(const std::string& _type, const CDetector_Params& _params) : - is_line_(false), is_limited_(false), keypoints_limit_(-1) + is_line_(false), is_limited_(false), keypoints_limit_(-1) { - is_init_ = init(_type, _params); - - if (!is_init_) - { - std::cerr << "[Feature Detector]: Something went wrong during initialization! Feature Detector not initialized." - << std::endl; - } -} + setAllTypes(); -CFeature_Detector::CFeature_Detector(const int& _type, const CDetector_Params& _params) : - is_line_(false), is_limited_(false), keypoints_limit_(-1) -{ - is_init_ = initFromInt(_type, _params); + is_init_ = init(_type, _params); if (!is_init_) { @@ -25,269 +15,25 @@ CFeature_Detector::CFeature_Detector(const int& _type, const CDetector_Params& _ } CFeature_Detector::CFeature_Detector(void) : - is_line_(false), is_limited_(false), keypoints_limit_(-1) + is_line_(false), is_limited_(false), keypoints_limit_(-1) { + setAllTypes(); } CFeature_Detector::~CFeature_Detector() { } -//CFeature_Detector::CFeature_Detector(const detector::Type& _type) : -// type_(detector::__DELIM__), is_line_(false), is_limited_(false), keypoints_limit_(-1) -//{ -// is_init_ = init(_type); -// -// if (!is_init_) -// { -// std::cerr << "[Feature Detector]: Something went wrong during initialization! Feature Detector not initialized." -// << std::endl; -// } -//} - -//CFeature_Detector::CFeature_Detector(const int&_type) : -// type_(detector::__DELIM__), is_line_(false), is_limited_(false), keypoints_limit_(-1) -//{ -// intToType(_type,type_); -// is_init_ = init(type_); -// -// if (!is_init_) -// { -// std::cerr << "[Feature Detector]: Something went wrong during initialization! Feature Detector not initialized." -// << std::endl; -// } -//} - -//CFeature_Detector::CFeature_Detector(void) : -// type_(detector::__DELIM__), is_line_(false), is_limited_(false), keypoints_limit_(-1) -//{ -//} - -//CFeature_Detector::~CFeature_Detector() -//{ -//} - -//std::vector<detector::Type> CFeature_Detector::list(void) -//{ -// std::vector<detector::Type> list; -// -// for (int ii = 0; ii < detector::__DELIM__; ii++) -// { -// list.push_back(static_cast<detector::Type>(ii)); -// } -// -// return list; -//} -// -//bool CFeature_Detector::setType(const detector::Type& _type) -//{ -// is_init_ = init(_type); -// return is_init_; -//} -// -//bool CFeature_Detector::setType(const int& _type) -//{ -// detector::Type type; -// intToType(_type, type); -// is_init_ = init(type); -// return is_init_; -//} -// -//bool CFeature_Detector::isLine(void) -//{ -// return is_line_; -//} -// -//bool CFeature_Detector::isLimited(void) -//{ -// return is_limited_; -//} -// -//int CFeature_Detector::getKeyPointsLimit(void) -//{ -// return keypoints_limit_; -//} - -//void CFeature_Detector::intToType(const unsigned int _i, detector::Type& _type) -//{ -// for (unsigned int ii = 0; ii < detector::__DELIM__; ii++) -// { -// if (ii == _i) -// _type = static_cast<detector::Type>(ii); -// } -//} -// -//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) -//{ -// cv::Mat mask = cv::Mat::ones(_image.size(), CV_8U); -// return detectKeyPoints(_image, mask); -//} -// -//CFeature_Detector::KeyPointVector CFeature_Detector::detectKeyPoints(const cv::Mat& _image, const cv::Mat& _mask) -//{ -// if (!is_init_) -// std::cerr << "[CFeature_Detector::detectKeyPoints]: Detector non initialized." << std::endl; -// -// KeyPointVector kpts; -// -// clock_t tStart = clock(); -// feature_detector_->detect(_image, kpts, _mask); -// comp_time_ = (double)(clock() - tStart) / CLOCKS_PER_SEC; -// -// if (isLimited()) -// { -// cv::KeyPointsFilter filter; -// filter.retainBest(kpts, this->getKeyPointsLimit()); -// } -// -// return kpts; -//} -// -//CFeature_Detector::KeyLineVector CFeature_Detector::detectKeyLines(const cv::Mat& _image) -//{ -// cv::Mat mask = cv::Mat::ones(_image.size(), CV_8U); -// return detectKeyLines(_image, mask); -//} -// -//CFeature_Detector::KeyLineVector CFeature_Detector::detectKeyLines(const cv::Mat& _image, const cv::Mat& _mask) -//{ -// if (!is_init_) -// std::cerr << "[CFeature_Detector::detectKeyLines]: Detector non initialized." << std::endl; -// -// KeyLineVector kls; -// KeyLineVector kls2; -// -// clock_t tStart = clock(); -// 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); -// comp_time_ = (double)(clock() - tStart) / CLOCKS_PER_SEC; -// kls.insert(kls.end(), kls2.begin(), kls2.end()); -// -// return kls; -//} -// -//bool CFeature_Detector::setLimitKeypts(unsigned int _nFeatures) -//{ -// if (_nFeatures > 0) -// { -// keypoints_limit_ = _nFeatures; -// return is_limited_ = true; -// } -// -// return false; -//} -// -//cv::Mat CFeature_Detector::drawKeyFeatures(const cv::Mat& _image, const KeyPointVector& _kp_vec) -//{ -// cv::Mat img_out(_image); -// -// for (unsigned int ii = 0; ii < _kp_vec.size(); ++ii) -// cv::circle(img_out, _kp_vec[ii].pt, 5, cv::Scalar(128, 128, 255), -1); -// -// return img_out; -//} -// -//cv::Mat CFeature_Detector::drawKeyFeatures(const cv::Mat& _image, const KeyLineVector& _kl_vec) -//{ -// cv::Mat img_out(_image); -// -// for (unsigned int ii = 0; ii < _kl_vec.size(); ++ii) -// cv::line(img_out, _kl_vec[ii].getStartPoint(), _kl_vec[ii].getEndPoint(), cv::Scalar(128, 128, 255), 3); -// -// return img_out; -//} - +void CFeature_Detector::setAllTypes(void) +{ + // Define all types + std::vector<std::string> types; + types += "FAST", "SIFT", "SURF", "ORB", "BRISK", "MSER", "GFTT", "HARRIS", "SBD", "KAZE", "AKAZE", "AGAST", "LSD", "ED"; + types_.set(types); +} bool CFeature_Detector::init(const std::string& _type, const CDetector_Params& _params) { - // Define detector types - std::vector<std::string> det_types; - det_types += "FAST", "SIFT", "SURF", "ORB", "BRISK", "MSER", "GFTT", "HARRIS", "SBD", "KAZE", "AKAZE", "AGAST", "LSD", "ED"; - types_.set(det_types); - if (is_init_) { std::cerr << "[CFeature_Detector::init]: Detector already initialized." << std::endl; @@ -295,40 +41,83 @@ bool CFeature_Detector::init(const std::string& _type, const CDetector_Params& _ } // TODO: Set parameters for each detector type - if (_type.compare(det_types[0])==0) + if (_type.compare(types_(0))==0) + { feature_detector_ = cv::FastFeatureDetector::create(); - else if (_type.compare(det_types[1])==0) + type_ = types_(0); + } + else if (_type.compare(types_(1))==0) + { feature_detector_ = cv::xfeatures2d::SIFT::create(); - else if (_type.compare(det_types[2])==0) + type_ = types_(1); + } + else if (_type.compare(types_(2))==0) + { feature_detector_ = cv::xfeatures2d::SURF::create(); - else if (_type.compare(det_types[3])==0) + type_ = types_(2); + } + else if (_type.compare(types_(3))==0) + { feature_detector_ = cv::ORB::create(); - else if (_type.compare(det_types[4])==0) + type_ = types_(3); + } + else if (_type.compare(types_(4))==0) + { feature_detector_ = cv::BRISK::create(); - else if (_type.compare(det_types[5])==0) + type_ = types_(4); + } + else if (_type.compare(types_(5))==0) + { feature_detector_ = cv::MSER::create(); - else if (_type.compare(det_types[6])==0) + type_ = types_(0); + } + else if (_type.compare(types_(6))==0) + { feature_detector_ = cv::GFTTDetector::create(1000, 0.01, 1.0, 3, false, 0.04); - else if (_type.compare(det_types[7])==0) + type_ = types_(6); + } + else if (_type.compare(types_(7))==0) + { feature_detector_ = cv::GFTTDetector::create(1000, 0.01, 1.0, 3, true, 0.04); - else if (_type.compare(det_types[8])==0) + type_ = types_(7); + } + else if (_type.compare(types_(8))==0) + { feature_detector_ = cv::SimpleBlobDetector::create(); - else if (_type.compare(det_types[9])==0) + type_ = types_(8); + } + else if (_type.compare(types_(9))==0) + { feature_detector_ = cv::KAZE::create(); - else if (_type.compare(det_types[10])==0) + type_ = types_(9); + } + else if (_type.compare(types_(10))==0) + { feature_detector_ = cv::AKAZE::create(); - else if (_type.compare(det_types[11])==0) + type_ = types_(10); + } + else if (_type.compare(types_(11))==0) + { feature_detector_ = cv::AgastFeatureDetector::create(); - else if (_type.compare(det_types[12])==0) + type_ = types_(11); + } + else if (_type.compare(types_(12))==0) + { lsd_detector_ = cv::line_descriptor::LSDDetector::createLSDDetector(); - else if (_type.compare(det_types[13])==0) + type_ = types_(12); + } + else if (_type.compare(types_(13))==0) + { ed_detector_ = cv::line_descriptor::BinaryDescriptor::createBinaryDescriptor(); + type_ = types_(13); + } else { std::cerr << "[Feature Detector]: detector_type " << _type << " doesn't exist !" << std::endl; return false; } + is_init_ = true; return true; } diff --git a/src/feature_detector/feature_detector.h b/src/feature_detector/feature_detector.h index 3bd8c04f4eb51106a2b633c089ec85438c5b9d71..ae04e8506ab3c407d72f2d3f5695517f22521b83 100644 --- a/src/feature_detector/feature_detector.h +++ b/src/feature_detector/feature_detector.h @@ -22,46 +22,6 @@ typedef cv::Ptr<cv::FeatureDetector> FeatureDetectorPtr; typedef cv::Ptr<cv::line_descriptor::LSDDetector> LSDDetector; typedef cv::Ptr<cv::line_descriptor::BinaryDescriptor> EDDetector; -//namespace detector { -// -///** -// * \brief MACROS to generate all detector types and their corresponding strings -// */ -//#define FOREACH_DETECTOR(DETECTOR) \ -// DETECTOR(FAST) \ -// DETECTOR(SIFT) \ -// DETECTOR(SURF) \ -// DETECTOR(ORB) \ -// DETECTOR(BRISK) \ -// DETECTOR(MSER) \ -// DETECTOR(GFTT) \ -// DETECTOR(HARRIS) \ -// DETECTOR(SBD) \ -// DETECTOR(KAZE) \ -// DETECTOR(AKAZE) \ -// DETECTOR(AGAST) \ -// DETECTOR(LSD) \ -// DETECTOR(ED) \ -// DETECTOR(__DELIM__) \ -// -//#define GENERATE_ENUM(ENUM) ENUM, -//#define GENERATE_STRING(STRING) #STRING, -//enum Type { -// FOREACH_DETECTOR(GENERATE_ENUM) -//}; -//static const char *DETECTOR_TYPE_STRING[] = -// { FOREACH_DETECTOR(GENERATE_STRING) }; -// -///** -// * \brief Stream operator for the detector flags. -// */ -//inline std::ostream& operator<<(std::ostream& _os, Type _f) { -// _os << DETECTOR_TYPE_STRING[_f]; -// return _os; -//} -// -//} // End of namespace - /** * \brief Feature detector parameters class */ @@ -78,40 +38,22 @@ public: /** * \brief Main feature detector class */ -class CFeature_Detector: public CVu_Base { +class CFeature_Detector: public CVu_Base <CDetector_Params> { public: - CTypes det_type_; - typedef std::vector<cv::KeyPoint> KeyPointVector; typedef std::vector<cv::line_descriptor::KeyLine> KeyLineVector; /** * \brief Constructor */ -// CFeature_Detector(const detector::Type& _type); -// CFeature_Detector(const int& _type); -// CFeature_Detector(void); - CFeature_Detector(const std::string& _type, const CDetector_Params& _params); - CFeature_Detector(const int& _type, const CDetector_Params& _params); CFeature_Detector(void); /** * \brief Destructor */ - ~CFeature_Detector(); - - /** - * \brief List the defined detector types - */ -// std::vector<detector::Type> list(void); - - /** - * \brief Set detector type - */ -// bool setType(const detector::Type& _type); -// bool setType(const int& _type); + ~CFeature_Detector(void); /** * \brief Inform if the detector searches points or lines @@ -151,8 +93,6 @@ public: private: -// detector::Type type_; - // Flags bool is_line_; bool is_limited_; @@ -163,20 +103,15 @@ private: LSDDetector lsd_detector_; // Feature line detector EDDetector ed_detector_; // Feature line detector + /** + * \brief Set all types + */ + void setAllTypes(void); + /** * \brief Initialize detector */ -// bool init(detector::Type _type); - bool init(const std::string &_type, const CDetector_Params &_params); - - /** - * \brief Convert an integer to its corresponding detector flag. - * - * By default return ORB. - */ -// void intToType(const unsigned int _i, detector::Type& _type); - }; #endif diff --git a/src/feature_matcher/feature_matcher.cpp b/src/feature_matcher/feature_matcher.cpp index 989af848e44fb3f41777f2ae6ae9ce1076bc791d..af8bf18aebcae5083b08c9a1c56d942b57afbfef 100644 --- a/src/feature_matcher/feature_matcher.cpp +++ b/src/feature_matcher/feature_matcher.cpp @@ -1,10 +1,10 @@ #include "feature_matcher.h" -CFeature_Matcher::CFeature_Matcher(const matcher::Type& _type) : - type_(matcher::__DELIM__) +CFeature_Matcher::CFeature_Matcher(const std::string& _type, const CMatcher_Params& _params) { + setAllTypes(); - is_init_ = init(_type); + is_init_ = init(_type, _params); if (!is_init_) { @@ -13,94 +13,71 @@ CFeature_Matcher::CFeature_Matcher(const matcher::Type& _type) : } } -CFeature_Matcher::CFeature_Matcher(const int& _type) : - type_(matcher::__DELIM__) -{ - - is_init_ = init(intToType(_type)); - - if (!is_init_) - { - std::cerr << "[Feature Matcher]: Something went wrong during initialization! Feature Matcher not initialized." - << std::endl; - } -} - -CFeature_Matcher::CFeature_Matcher(void) : - type_(matcher::__DELIM__) +CFeature_Matcher::CFeature_Matcher(void) { + setAllTypes(); } CFeature_Matcher::~CFeature_Matcher(void) { } -std::vector<matcher::Type> CFeature_Matcher::list(void) +void CFeature_Matcher::setAllTypes(void) { - std::vector<matcher::Type> list; - - for (int ii = 0; ii < matcher::__DELIM__; ii++) - { - list.push_back(static_cast<matcher::Type>(ii)); - } - - return list; + // Define all types + std::vector<std::string> types; + types += "FlannBased", "BruteForce", "BruteForce-L1", "BruteForce-Hamming", "BruteForce-Hamming(2)"; + types_.set(types); } -bool CFeature_Matcher::setType(const matcher::Type& _type) -{ - is_init_ = init(_type); - return is_init_; -} -bool CFeature_Matcher::setType(const int& _type) +bool CFeature_Matcher::init(const std::string& _type, const CMatcher_Params& _params) { - is_init_ = init(intToType(_type)); - return is_init_; -} - -bool CFeature_Matcher::init(matcher::Type _type) { if (is_init_) + { std::cerr << "[CFeature_Matcher::init]: Matcher already initialized." << std::endl; + return false; + } + + std::cout << _type << std::endl; - bool success = false; // TODO: Set parameters for each matcher type - switch (_type) { - case matcher::BF_NORM_L1: - feature_matcher_ = cv::DescriptorMatcher::create("BF_NORM_L1"); - success = true; - break; - case matcher::BF_NORM_L2: - feature_matcher_ = cv::DescriptorMatcher::create("BF_NORM_L2"); - success = true; - break; - case matcher::BF_NORM_HAMMING: - feature_matcher_ = cv::DescriptorMatcher::create("BF_NORM_HAMMING"); - success = true; - break; - case matcher::BF_NORM_HAMMING2: - feature_matcher_ = cv::DescriptorMatcher::create("BF_NORM_HAMMING2"); - success = true; - break; - case matcher::FlannBased: - feature_matcher_ = cv::DescriptorMatcher::create("FlannBased"); - success = true; - break; - case matcher::__DELIM__: - success = false; - break; + if (_type.compare(types_(0))==0) + { + feature_matcher_ = cv::DescriptorMatcher::create(_type); + type_ = types_(0); + } + else if (_type.compare(types_(1))==0) + { + feature_matcher_ = cv::DescriptorMatcher::create(_type); + type_ = types_(1); + } + else if (_type.compare(types_(2))==0) + { + feature_matcher_ = cv::DescriptorMatcher::create(_type); + type_ = types_(2); + } + else if (_type.compare(types_(3))==0) + { + feature_matcher_ = cv::DescriptorMatcher::create(_type); + type_ = types_(3); + } + else if (_type.compare(types_(4))==0) + { + feature_matcher_ = cv::DescriptorMatcher::create(_type); + type_ = types_(4); } - - if (success) - type_ = _type; else - std::cerr << "[Feature Matcher]: mathcer_type " << _type - << " doesn't exist !" << std::endl; + { + std::cerr << "[Feature Matcher]: mathcer_type " << _type << " doesn't exist !" << std::endl; + return false; + } - return success; + is_init_ = true; + return true; } @@ -120,15 +97,5 @@ bool CFeature_Matcher::init(matcher::Type _type) { // return descriptors; //} -matcher::Type CFeature_Matcher::intToType( - const unsigned int _i) { - matcher::Type type; - - for (unsigned int ii = 0; ii < matcher::__DELIM__; ii++) { - if (ii == _i) - type = static_cast<matcher::Type>(ii); - } - return type; -} diff --git a/src/feature_matcher/feature_matcher.h b/src/feature_matcher/feature_matcher.h index d6c2eec0eac79f679595a54c4d558ba39d11ec95..e13f44cde116fc03515b94d0cda22ddf9bc85aaa 100644 --- a/src/feature_matcher/feature_matcher.h +++ b/src/feature_matcher/feature_matcher.h @@ -18,58 +18,28 @@ typedef cv::Ptr<cv::DescriptorMatcher> FeatureMatcherPtr; -namespace matcher { - /** - * \brief MACROS to generate all matcher types and their corresponding strings + * \brief Feature descriptor parameters class */ -#define FOREACH_MATCHER(MATCHER) \ - MATCHER(BF_NORM_L1) \ - MATCHER(BF_NORM_L2) \ - MATCHER(BF_NORM_HAMMING) \ - MATCHER(BF_NORM_HAMMING2) \ - MATCHER(FlannBased) \ - MATCHER(__DELIM__) \ - -#define GENERATE_ENUM(ENUM) ENUM, -#define GENERATE_STRING(STRING) #STRING, -enum Type { - FOREACH_MATCHER(GENERATE_ENUM) +class CMatcher_Params: public CParams { +public: + CMatcher_Params(void) { + } + ; + ~CMatcher_Params(void) { + } + ; }; -static const char *MATCHER_TYPE_STRING[] = { FOREACH_MATCHER( - GENERATE_STRING) }; - -/** - * \brief Stream operator for the matcher flags. - */ -inline std::ostream& operator<<(std::ostream& _os, Type _f) { - _os << MATCHER_TYPE_STRING[_f]; - return _os; -} -} // end of namespace - -class CFeature_Matcher: public CVu_Base +class CFeature_Matcher: public CVu_Base<CMatcher_Params> { public: - CFeature_Matcher(const matcher::Type& _type); - CFeature_Matcher(const int& _type); + CFeature_Matcher(const std::string& _type, const CMatcher_Params& _params); CFeature_Matcher(void); ~CFeature_Matcher(void); - /** - * \brief List the defined types - */ - std::vector<matcher::Type> list(void); - - /** - * \brief Set type - */ - bool setType(const matcher::Type& _type); - bool setType(const int& _type); - /** * \brief Match */ @@ -78,22 +48,17 @@ class CFeature_Matcher: public CVu_Base private: - matcher::Type type_; - FeatureMatcherPtr feature_matcher_; // Feature matcher /** - * \brief Initialize matcher + * \brief Set all types */ - bool init(matcher::Type _type); + void setAllTypes(void); /** - * \brief Convert an integer to its corresponding descriptor flag. - * + * \brief Initialize matcher */ - matcher::Type intToType(const unsigned int _i); - - + bool init(const std::string &_type, const CMatcher_Params &_params); }; #endif diff --git a/src/vision_utils.h b/src/vision_utils.h index ec36cf19ba3564d8a3822bcd504fbe9f3b178a4f..7a2d44d795d59e36d704cd8f49d81170bd70d7d4 100644 --- a/src/vision_utils.h +++ b/src/vision_utils.h @@ -4,6 +4,7 @@ #include "cam_utils/cam_utils.h" #include "feature_detector/feature_detector.h" #include "feature_descriptor/feature_descriptor.h" +#include "feature_matcher/feature_matcher.h" #include <functional> #include <set> diff --git a/src/vu_base/vu_base.cpp b/src/vu_base/vu_base.cpp deleted file mode 100644 index eb7967afd2bee59fe2558963d79acb0a2661b6ac..0000000000000000000000000000000000000000 --- a/src/vu_base/vu_base.cpp +++ /dev/null @@ -1,48 +0,0 @@ -#include "vu_base.h" - -CVu_Base::CVu_Base(void): is_init_(false), comp_time_(0.0) -{ -} - -CVu_Base::~CVu_Base(void) { -} - -double CVu_Base::getTime(void) -{ - return comp_time_; -} - -bool CVu_Base::init(const std::string &_type, const CParams &_params) -{ - return false; -} - -bool CVu_Base::initFromInt(const int &_type, const CParams &_params) -{ - std::string name = types_(_type); - return init(name,_params); -} - -std::vector<std::string> CVu_Base::list(void) -{ - std::vector<std::string> list; - list.reserve(types_.size()); - for (unsigned int ii = 0; ii < types_.size(); ii++) - { - std::string name = types_(ii); - list.push_back(name); - } - return list; -} - -bool CVu_Base::set(const std::string& _type, const CParams &_params) -{ - is_init_ = init(_type, _params); - return is_init_; -} - -bool CVu_Base::set(const int& _type, const CParams &_params) -{ - is_init_ = initFromInt(_type, _params); - return is_init_; -} diff --git a/src/vu_base/vu_base.h b/src/vu_base/vu_base.h index 135bdd127a623d642149f1a360b61aab573b513c..9c1af28563c26c17bcba9100dffb5b08a8498535 100644 --- a/src/vu_base/vu_base.h +++ b/src/vu_base/vu_base.h @@ -27,10 +27,19 @@ public: void set(std::vector<std::string> &_types) { for (unsigned int ii = 0; ii < _types.size(); ii++) - { types_[_types[ii]] = ii; } + types_[_types[ii]] = ii; init_= true; }; + std::vector<std::string> list(void) + { + std::vector<std::string> list; + list.reserve(types_.size()); + for(std::map<std::string,int>::iterator it = types_.begin(); it != types_.end(); ++it) + list.push_back(it->first); + return list; + } + int operator()(const std::string &name) { if (init_) { @@ -80,32 +89,52 @@ public: ; }; + +/** + * \brief Superbase Class + * + * This Super class is created in order to work with pointers to the derived + * classes. Otherwise CSensor_base is templated and does not allow it. + */ +class CVu_Superbase +{ +public: + CVu_Superbase(){}; + virtual ~CVu_Superbase(){}; + +}; + /** * \brief base Class */ -class CVu_Base { +template <class T_PARAMS> +class CVu_Base: public CVu_Superbase { public: - CVu_Base(void); + CVu_Base(void): is_init_(false) {}; - ~CVu_Base(void); + virtual ~CVu_Base(void){}; /** * \brief Get detection duration */ - double getTime(void); + double getTime(void){return comp_time_;}; /** * \brief list types */ - std::vector<std::string> list(void); + std::vector<std::string> list(void) + { return types_.list();}; /** * \brief Set object without constructor */ - bool set(const std::string& _type, const CParams &_params); - bool set(const int& _type, const CParams &_params); + bool set(const std::string& _type, const T_PARAMS &_params) + { + bool success = init(_type, _params); + return success; + }; protected: @@ -118,8 +147,13 @@ protected: std::string type_; - virtual bool init(const std::string &_type, const CParams &_params); - bool initFromInt(const int &_type, const CParams &_params); + virtual bool init(const std::string &_type, const T_PARAMS &_params) = 0; + + /** + * \brief Set all types + */ + virtual void setAllTypes(void) = 0; + }; #endif