diff --git a/src/examples/feature_detect.cpp b/src/examples/feature_detect.cpp index 5f3dc8fbc8d113935303338e9b9e45c12fbb327f..7dae60b028c05cb5f55133d039e344dcc50b4e16 100644 --- a/src/examples/feature_detect.cpp +++ b/src/examples/feature_detect.cpp @@ -20,12 +20,24 @@ int main(int argc, char *argv[]) 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?: "; + //*********** + // Detector | + //*********** + + // Get default value int feat_type; - std::cin >> feat_type; + detector.get(feat_type); + + std::cout << std::endl << "Which DETECTOR do you want to test?[default: " << detectors_list[feat_type] << "]"; + + feat_type = readFromUser(feat_type); + detector.set(detectors_list[feat_type],detector_params); + std::cout << std::endl << "Testing: " << detectors_list[feat_type] << std::endl; + // ***************************** + // Open camera cv::VideoCapture cam; CCamUtils cam_fc; diff --git a/src/examples/feature_detect_descript.cpp b/src/examples/feature_detect_descript.cpp index f6bea26e86c6b55ce730486275961c7be88ce2a9..f4ba26456b2b65603bd0ebe9db770286ad7400b9 100644 --- a/src/examples/feature_detect_descript.cpp +++ b/src/examples/feature_detect_descript.cpp @@ -11,6 +11,10 @@ int main(int argc, char *argv[]) std::cout << "---------------------------------------------------------" << std::endl; std::cout << std::endl; + //*********** + // Detector | + //*********** + CFeature_Detector detector; CDetector_Params detector_params; // TODO: Fill parameters @@ -23,11 +27,19 @@ int main(int argc, char *argv[]) std::cout << "[" << ii << "]: " << detectors_list[ii] << std::endl; } - std::cout << std::endl << "Which DETECTOR do you want to test?: "; + // Get default value int feat_type; - std::cin >> feat_type; + detector.get(feat_type); + + std::cout << std::endl << "Which DETECTOR do you want to test?[default: " << detectors_list[feat_type] << "]"; + + feat_type = readFromUser(feat_type); + detector.set(detectors_list[feat_type],detector_params); - std::cout << std::endl << "Testing: " << detectors_list[feat_type] << std::endl; + + //************* + // Descriptor | + //************* CFeature_Descriptor descriptor; CDescriptor_Params descriptor_params; // TODO: Fill parameters @@ -38,12 +50,20 @@ int main(int argc, char *argv[]) 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?: "; + // Get default value int desc_type; - std::cin >> desc_type; + descriptor.get(desc_type); + + std::cout << std::endl << "Which DESCRIPTOR do you want to test?[default: " << descriptor_list[desc_type] << "]"; + + desc_type = readFromUser(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; diff --git a/src/examples/feature_detect_descript_match.cpp b/src/examples/feature_detect_descript_match.cpp index e4781450931b4cb3d8c2c885188caa969e48bd41..5b3b7eb716cd27e8f9abe46e4a83fd8614c08c75 100644 --- a/src/examples/feature_detect_descript_match.cpp +++ b/src/examples/feature_detect_descript_match.cpp @@ -2,7 +2,7 @@ #include <string> #include "vision_utils.h" - +#include <sstream> int main(int argc, char *argv[]) { @@ -11,83 +11,117 @@ int main(int argc, char *argv[]) std::cout << "-------------------------------------------------------------------" << std::endl; std::cout << std::endl; - CFeature_Detector detector; - CDetector_Params detector_params; // TODO: Fill parameters + //*********** + // Detector | + //*********** - std::vector<std::string> detectors_list; - detectors_list = detector.list(); + CFeature_Detector detector; + CDetector_Params detector_params; // TODO: Fill parameters - 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::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; + } + + // Get default value + int feat_type; + detector.get(feat_type); + + std::cout << std::endl << "Which DETECTOR do you want to test?[default: " << detectors_list[feat_type] << "]"; + + feat_type = readFromUser(feat_type); + + detector.set(detectors_list[feat_type],detector_params); + + //************* + // Descriptor | + //************* + + 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; + + // Get default value + int desc_type; + descriptor.get(desc_type); + + std::cout << std::endl << "Which DESCRIPTOR do you want to test?[default: " << descriptor_list[desc_type] << "]"; + + desc_type = readFromUser(desc_type); + + descriptor.set(descriptor_list[desc_type],descriptor_params); + + //********** + // Matcher | + //********** + + CFeature_Matcher matcher; + CMatcher_Params matcher_params; // TODO: Fill parameters + CMatcher_Params matcher_search_params; // TODO: Fill parameters + + std::vector<std::string> matchers_list; + matchers_list = matcher.list(); - 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); + for (unsigned int ii=0; ii<matchers_list.size(); ii++) + std::cout << "[" << ii << "]: " << matchers_list[ii] << std::endl; - CFeature_Descriptor descriptor; - CDescriptor_Params descriptor_params; // TODO: Fill parameters + // Get default value + int match_type; + matcher.get(match_type); - std::vector<std::string> descriptor_list; - descriptor_list = descriptor.list(); + std::cout << std::endl << "Which MATCHER do you want to test?[default: " << matchers_list[match_type] << "]"; - for (unsigned int ii=0; ii<descriptor_list.size(); ii++) - std::cout << "[" << ii << "]: " << descriptor_list[ii] << std::endl; + match_type = readFromUser(match_type); - 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); + matcher.set(matchers_list[match_type],matcher_params); - CFeature_Matcher matcher; - CMatcher_Params matcher_params; // TODO: Fill parameters - CMatcher_Params matcher_search_params; // TODO: Fill parameters + std::vector<std::string> matchers_search_list; + matchers_search_list = matcher.listSearchTypes(); - std::vector<std::string> matchers_list; - matchers_list = matcher.list(); + for (unsigned int ii=0; ii<matchers_search_list.size(); ii++) + std::cout << "[" << ii << "]: " << matchers_search_list[ii] << std::endl; - for (unsigned int ii=0; ii<matchers_list.size(); ii++) - std::cout << "[" << ii << "]: " << matchers_list[ii] << std::endl; + // Get default value + int match_search_type; + matcher.get(match_search_type); - 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 << "Which MATCHER do you want to test?[default: " << matchers_search_list[match_search_type] << "]"; - std::vector<std::string> matchers_out_list; - matchers_out_list = matcher.listSearchTypes(); + match_search_type = readFromUser(match_search_type); - for (unsigned int ii=0; ii<matchers_out_list.size(); ii++) - std::cout << "[" << ii << "]: " << matchers_out_list[ii] << std::endl; + matcher.setSearchType(matchers_search_list[match_search_type],matcher_search_params); - std::cout << std::endl << "Which MATCHER SEARCH do you want to test?: "; - int match_search_type; - std::cin >> match_search_type; - matcher.setSearchType(matchers_out_list[match_search_type],matcher_search_params); + std::cout << std::endl << "Testing: " << detectors_list[feat_type] << " + " << descriptor_list[desc_type] << " + " << matchers_list[match_type] << " + " << matchers_search_list[match_search_type] << " (DETECTOR + DESCRIPTOR + MATCHER + MATCHER SEARCH)" << std::endl; - std::cout << std::endl << "Testing: " << detectors_list[feat_type] << " + " << descriptor_list[desc_type] << " + " << matchers_list[match_type] << " + " << matchers_out_list[match_search_type] << " (DETECTOR + DESCRIPTOR + MATCHER + MATCHER SEARCH)" << std::endl; + // ***************************** - // matcher objects - KeyPointVector keypoints_old; + // matcher objects + KeyPointVector keypoints_old; - // Open camera - cv::VideoCapture cam; - CCamUtils cam_fc; - cam_fc.openCamera(0, cam); + // 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); + // 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; + // 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) - { + for (int nframe = 0; nframe < 1000; ++nframe) + { // Get frame cv::Mat frame; cam_fc.getFrame(cam, frame); diff --git a/src/feature_descriptor/feature_descriptor.cpp b/src/feature_descriptor/feature_descriptor.cpp index bb11a416d8b755671cba3dadde74e92f3157f1ca..86c6fab37ca702f7e974c363513b264ddb79dd4e 100644 --- a/src/feature_descriptor/feature_descriptor.cpp +++ b/src/feature_descriptor/feature_descriptor.cpp @@ -28,6 +28,7 @@ void CFeature_Descriptor::setAllTypes(void) std::vector<std::string> types; types += "ORB", "SIFT", "SURF", "KAZE", "AKAZE", "BRISK", "LATCH", "FREAK", "BRIEF", "DAISY", "LUCID"; types_.set(types); + type_ = "ORB"; // Default value } bool CFeature_Descriptor::init(const std::string& _type, const CDescriptor_Params& _params) diff --git a/src/feature_detector/feature_detector.cpp b/src/feature_detector/feature_detector.cpp index be6ee85469f3b229a184ce8178fb651c735a3cba..9dacdec7fe9bd6d80213185a937893c25a5c369a 100644 --- a/src/feature_detector/feature_detector.cpp +++ b/src/feature_detector/feature_detector.cpp @@ -30,6 +30,7 @@ void CFeature_Detector::setAllTypes(void) std::vector<std::string> types; types += "FAST", "SIFT", "SURF", "ORB", "BRISK", "MSER", "GFTT", "HARRIS", "SBD", "KAZE", "AKAZE", "AGAST", "LSD", "ED"; types_.set(types); + type_ = "ORB"; // Default value } bool CFeature_Detector::init(const std::string& _type, const CDetector_Params& _params) diff --git a/src/feature_matcher/feature_matcher.cpp b/src/feature_matcher/feature_matcher.cpp index 34ff0b3722fc0ae7b645a745b1220539f6efb1a5..32b15f1715744e0141be3bb8f7821cf4a7ee2d4f 100644 --- a/src/feature_matcher/feature_matcher.cpp +++ b/src/feature_matcher/feature_matcher.cpp @@ -28,12 +28,12 @@ void CFeature_Matcher::setAllTypes(void) std::vector<std::string> types; types += "FlannBased", "BruteForce", "BruteForce-L1", "BruteForce-Hamming", "BruteForce-Hamming(2)"; types_.set(types); + type_ = "BruteForce"; // Default value // Define all match output variants std::vector<std::string> out_types; out_types += "Match", "knnMartch", "radiusMatch"; match_search_types_.set(out_types); - match_search_type_ = "Match"; // Default value } diff --git a/src/vision_utils.h b/src/vision_utils.h index 7a2d44d795d59e36d704cd8f49d81170bd70d7d4..24d4b21570c1b2a9ef5b40ee2fc89ee133bf88be 100644 --- a/src/vision_utils.h +++ b/src/vision_utils.h @@ -15,4 +15,20 @@ public: ~CVision_Utils(); }; +template <typename T> +T readFromUser(const T& def_num) +{ + T read = def_num; + std::string input; + std::getline( std::cin, input ); + if ( !input.empty() ) + { + std::istringstream stream( input ); + stream >> read; + } + + return read; +} + + #endif diff --git a/src/vu_base/vu_base.h b/src/vu_base/vu_base.h index e6e57abc20abffd44a386d26f0dbd0bf6f920f73..b35c0595b7420ffac51af40bda4b98ce30ace379 100644 --- a/src/vu_base/vu_base.h +++ b/src/vu_base/vu_base.h @@ -51,16 +51,26 @@ public: { 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); + 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_) { - std::map<std::string, int>::const_iterator it = types_.find(name); - return it->second; + // Search done to take advantage of MAP alphabetical order + int idx = 0; + for (std::map<std::string, int>::const_iterator it = types_.begin();it != types_.end(); ++it) + { + if (it->first.compare(name) == 0) + return idx; + ++idx; + } + + } else { @@ -72,10 +82,13 @@ public: std::string operator()(const int &num) { if (init_) { + // Search done to take advantage of MAP alphabetical order + int idx = 0; for (std::map<std::string, int>::const_iterator it = types_.begin();it != types_.end(); ++it) { - if (it->second == num) + if (num == idx) return it->first; + ++idx; } } else @@ -141,7 +154,7 @@ public: * \brief list types */ std::vector<std::string> list(void) - { return types_.list();}; + { return types_.list();}; /** * \brief Set object without constructor @@ -152,6 +165,14 @@ public: return success; }; + void get(std::string& _type) + { _type = type_; }; + + void get(int& _type) + { + _type = types_(type_); + }; + cv::Mat drawKeyFeatures(const cv::Mat& _image, const KeyPointVector& _kp_vec) { cv::Mat img_out(_image);