Skip to content
Snippets Groups Projects
Commit d83a1b0c authored by Angel Santamaria-Navarro's avatar Angel Santamaria-Navarro
Browse files

added function to read from user and fixed problem with map alphabetical order...

added function to read from user and fixed problem with map alphabetical order of types_ in base class
parent cdb7e195
No related branches found
No related tags found
No related merge requests found
...@@ -20,12 +20,24 @@ int main(int argc, char *argv[]) ...@@ -20,12 +20,24 @@ int main(int argc, char *argv[])
for (unsigned int ii=0; ii<detectors_list.size(); ii++) for (unsigned int ii=0; ii<detectors_list.size(); ii++)
std::cout << "[" << ii << "]: " << detectors_list[ii] << std::endl; 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; 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); detector.set(detectors_list[feat_type],detector_params);
std::cout << std::endl << "Testing: " << detectors_list[feat_type] << std::endl; std::cout << std::endl << "Testing: " << detectors_list[feat_type] << std::endl;
// *****************************
// Open camera // Open camera
cv::VideoCapture cam; cv::VideoCapture cam;
CCamUtils cam_fc; CCamUtils cam_fc;
......
...@@ -11,6 +11,10 @@ int main(int argc, char *argv[]) ...@@ -11,6 +11,10 @@ int main(int argc, char *argv[])
std::cout << "---------------------------------------------------------" << std::endl; std::cout << "---------------------------------------------------------" << std::endl;
std::cout << std::endl; std::cout << std::endl;
//***********
// Detector |
//***********
CFeature_Detector detector; CFeature_Detector detector;
CDetector_Params detector_params; // TODO: Fill parameters CDetector_Params detector_params; // TODO: Fill parameters
...@@ -23,11 +27,19 @@ int main(int argc, char *argv[]) ...@@ -23,11 +27,19 @@ int main(int argc, char *argv[])
std::cout << "[" << ii << "]: " << detectors_list[ii] << std::endl; 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; 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); detector.set(detectors_list[feat_type],detector_params);
std::cout << std::endl << "Testing: " << detectors_list[feat_type] << std::endl;
//*************
// Descriptor |
//*************
CFeature_Descriptor descriptor; CFeature_Descriptor descriptor;
CDescriptor_Params descriptor_params; // TODO: Fill parameters CDescriptor_Params descriptor_params; // TODO: Fill parameters
...@@ -38,12 +50,20 @@ int main(int argc, char *argv[]) ...@@ -38,12 +50,20 @@ int main(int argc, char *argv[])
for (unsigned int ii=0; ii<descriptor_list.size(); ii++) for (unsigned int ii=0; ii<descriptor_list.size(); ii++)
std::cout << "[" << ii << "]: " << descriptor_list[ii] << std::endl; 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; 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); 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; std::cout << std::endl << "Testing: " << detectors_list[feat_type] << " + " << descriptor_list[desc_type] << " (DETECTOR + DESCRIPTOR)" << std::endl;
// *****************************
// Open camera // Open camera
cv::VideoCapture cam; cv::VideoCapture cam;
CCamUtils cam_fc; CCamUtils cam_fc;
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
#include <string> #include <string>
#include "vision_utils.h" #include "vision_utils.h"
#include <sstream>
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
...@@ -11,83 +11,117 @@ int main(int argc, char *argv[]) ...@@ -11,83 +11,117 @@ int main(int argc, char *argv[])
std::cout << "-------------------------------------------------------------------" << std::endl; std::cout << "-------------------------------------------------------------------" << std::endl;
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; CFeature_Detector detector;
detectors_list = detector.list(); CDetector_Params detector_params; // TODO: Fill parameters
for (unsigned int ii=0; ii<detectors_list.size(); ii++) std::vector<std::string> detectors_list;
{ detectors_list = detector.list();
if ( (detectors_list[ii].compare("LSD")!=0) && (detectors_list[ii].compare("ED")!=0) )
std::cout << "[" << ii << "]: " << detectors_list[ii] << std::endl; 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?: "; for (unsigned int ii=0; ii<matchers_list.size(); ii++)
int feat_type; std::cout << "[" << ii << "]: " << matchers_list[ii] << std::endl;
std::cin >> feat_type;
detector.set(detectors_list[feat_type],detector_params);
CFeature_Descriptor descriptor; // Get default value
CDescriptor_Params descriptor_params; // TODO: Fill parameters int match_type;
matcher.get(match_type);
std::vector<std::string> descriptor_list; std::cout << std::endl << "Which MATCHER do you want to test?[default: " << matchers_list[match_type] << "]";
descriptor_list = descriptor.list();
for (unsigned int ii=0; ii<descriptor_list.size(); ii++) match_type = readFromUser(match_type);
std::cout << "[" << ii << "]: " << descriptor_list[ii] << std::endl;
std::cout << std::endl << "Which DESCRIPTOR do you want to test?: "; matcher.set(matchers_list[match_type],matcher_params);
int desc_type;
std::cin >> desc_type;
descriptor.set(descriptor_list[desc_type],descriptor_params);
CFeature_Matcher matcher; std::vector<std::string> matchers_search_list;
CMatcher_Params matcher_params; // TODO: Fill parameters matchers_search_list = matcher.listSearchTypes();
CMatcher_Params matcher_search_params; // TODO: Fill parameters
std::vector<std::string> matchers_list; for (unsigned int ii=0; ii<matchers_search_list.size(); ii++)
matchers_list = matcher.list(); std::cout << "[" << ii << "]: " << matchers_search_list[ii] << std::endl;
for (unsigned int ii=0; ii<matchers_list.size(); ii++) // Get default value
std::cout << "[" << ii << "]: " << matchers_list[ii] << std::endl; int match_search_type;
matcher.get(match_search_type);
std::cout << std::endl << "Which MATCHER do you want to test?: "; std::cout << std::endl << "Which MATCHER do you want to test?[default: " << matchers_search_list[match_search_type] << "]";
int match_type;
std::cin >> match_type;
matcher.set(matchers_list[match_type],matcher_params);
std::vector<std::string> matchers_out_list; match_search_type = readFromUser(match_search_type);
matchers_out_list = matcher.listSearchTypes();
for (unsigned int ii=0; ii<matchers_out_list.size(); ii++) matcher.setSearchType(matchers_search_list[match_search_type],matcher_search_params);
std::cout << "[" << ii << "]: " << matchers_out_list[ii] << std::endl;
std::cout << std::endl << "Which MATCHER SEARCH do you want to test?: "; 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;
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_out_list[match_search_type] << " (DETECTOR + DESCRIPTOR + MATCHER + MATCHER SEARCH)" << std::endl; // *****************************
// matcher objects // matcher objects
KeyPointVector keypoints_old; KeyPointVector keypoints_old;
// Open camera // Open camera
cv::VideoCapture cam; cv::VideoCapture cam;
CCamUtils cam_fc; CCamUtils cam_fc;
cam_fc.openCamera(0, cam); cam_fc.openCamera(0, cam);
// Create displays // Create displays
cv::startWindowThread(); cv::startWindowThread();
cv::namedWindow("Original image", cv::WINDOW_NORMAL); cv::namedWindow("Original image", cv::WINDOW_NORMAL);
cv::namedWindow("Detections", cv::WINDOW_NORMAL); cv::namedWindow("Detections", cv::WINDOW_NORMAL);
// The following line is used to remove the OpenCV "init done" from the terminal // The following line is used to remove the OpenCV "init done" from the terminal
std::cout << "\e[A" << " " << std::endl; std::cout << "\e[A" << " " << std::endl;
for (int nframe = 0; nframe < 1000; ++nframe) for (int nframe = 0; nframe < 1000; ++nframe)
{ {
// Get frame // Get frame
cv::Mat frame; cv::Mat frame;
cam_fc.getFrame(cam, frame); cam_fc.getFrame(cam, frame);
......
...@@ -28,6 +28,7 @@ void CFeature_Descriptor::setAllTypes(void) ...@@ -28,6 +28,7 @@ void CFeature_Descriptor::setAllTypes(void)
std::vector<std::string> types; std::vector<std::string> types;
types += "ORB", "SIFT", "SURF", "KAZE", "AKAZE", "BRISK", "LATCH", "FREAK", "BRIEF", "DAISY", "LUCID"; types += "ORB", "SIFT", "SURF", "KAZE", "AKAZE", "BRISK", "LATCH", "FREAK", "BRIEF", "DAISY", "LUCID";
types_.set(types); types_.set(types);
type_ = "ORB"; // Default value
} }
bool CFeature_Descriptor::init(const std::string& _type, const CDescriptor_Params& _params) bool CFeature_Descriptor::init(const std::string& _type, const CDescriptor_Params& _params)
......
...@@ -30,6 +30,7 @@ void CFeature_Detector::setAllTypes(void) ...@@ -30,6 +30,7 @@ void CFeature_Detector::setAllTypes(void)
std::vector<std::string> types; std::vector<std::string> types;
types += "FAST", "SIFT", "SURF", "ORB", "BRISK", "MSER", "GFTT", "HARRIS", "SBD", "KAZE", "AKAZE", "AGAST", "LSD", "ED"; types += "FAST", "SIFT", "SURF", "ORB", "BRISK", "MSER", "GFTT", "HARRIS", "SBD", "KAZE", "AKAZE", "AGAST", "LSD", "ED";
types_.set(types); types_.set(types);
type_ = "ORB"; // Default value
} }
bool CFeature_Detector::init(const std::string& _type, const CDetector_Params& _params) bool CFeature_Detector::init(const std::string& _type, const CDetector_Params& _params)
......
...@@ -28,12 +28,12 @@ void CFeature_Matcher::setAllTypes(void) ...@@ -28,12 +28,12 @@ void CFeature_Matcher::setAllTypes(void)
std::vector<std::string> types; std::vector<std::string> types;
types += "FlannBased", "BruteForce", "BruteForce-L1", "BruteForce-Hamming", "BruteForce-Hamming(2)"; types += "FlannBased", "BruteForce", "BruteForce-L1", "BruteForce-Hamming", "BruteForce-Hamming(2)";
types_.set(types); types_.set(types);
type_ = "BruteForce"; // Default value
// Define all match output variants // Define all match output variants
std::vector<std::string> out_types; std::vector<std::string> out_types;
out_types += "Match", "knnMartch", "radiusMatch"; out_types += "Match", "knnMartch", "radiusMatch";
match_search_types_.set(out_types); match_search_types_.set(out_types);
match_search_type_ = "Match"; // Default value match_search_type_ = "Match"; // Default value
} }
......
...@@ -15,4 +15,20 @@ public: ...@@ -15,4 +15,20 @@ public:
~CVision_Utils(); ~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 #endif
...@@ -51,16 +51,26 @@ public: ...@@ -51,16 +51,26 @@ public:
{ {
std::vector<std::string> list; std::vector<std::string> list;
list.reserve(types_.size()); list.reserve(types_.size());
for(std::map<std::string,int>::iterator it = types_.begin(); it != types_.end(); ++it) for(std::map<std::string,int>::iterator it = types_.begin(); it != types_.end(); ++it)
list.push_back(it->first); {
list.push_back(it->first);
}
return list; return list;
} }
int operator()(const std::string &name) { int operator()(const std::string &name) {
if (init_) if (init_)
{ {
std::map<std::string, int>::const_iterator it = types_.find(name); // Search done to take advantage of MAP alphabetical order
return it->second; 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 else
{ {
...@@ -72,10 +82,13 @@ public: ...@@ -72,10 +82,13 @@ public:
std::string operator()(const int &num) { std::string operator()(const int &num) {
if (init_) 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) 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; return it->first;
++idx;
} }
} }
else else
...@@ -141,7 +154,7 @@ public: ...@@ -141,7 +154,7 @@ public:
* \brief list types * \brief list types
*/ */
std::vector<std::string> list(void) std::vector<std::string> list(void)
{ return types_.list();}; { return types_.list();};
/** /**
* \brief Set object without constructor * \brief Set object without constructor
...@@ -152,6 +165,14 @@ public: ...@@ -152,6 +165,14 @@ public:
return success; 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 drawKeyFeatures(const cv::Mat& _image, const KeyPointVector& _kp_vec)
{ {
cv::Mat img_out(_image); cv::Mat img_out(_image);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment