diff --git a/src/examples/feature_detect_descript_match.cpp b/src/examples/feature_detect_descript_match.cpp index 5b3b7eb716cd27e8f9abe46e4a83fd8614c08c75..02658d161a087a116102bbd49415f74762af10f0 100644 --- a/src/examples/feature_detect_descript_match.cpp +++ b/src/examples/feature_detect_descript_match.cpp @@ -33,7 +33,7 @@ int main(int argc, char *argv[]) std::cout << std::endl << "Which DETECTOR do you want to test?[default: " << detectors_list[feat_type] << "]"; - feat_type = readFromUser(feat_type); +// feat_type = readFromUser(feat_type); detector.set(detectors_list[feat_type],detector_params); @@ -56,7 +56,7 @@ int main(int argc, char *argv[]) std::cout << std::endl << "Which DESCRIPTOR do you want to test?[default: " << descriptor_list[desc_type] << "]"; - desc_type = readFromUser(desc_type); +// desc_type = readFromUser(desc_type); descriptor.set(descriptor_list[desc_type],descriptor_params); @@ -80,7 +80,7 @@ int main(int argc, char *argv[]) std::cout << std::endl << "Which MATCHER do you want to test?[default: " << matchers_list[match_type] << "]"; - match_type = readFromUser(match_type); +// match_type = readFromUser(match_type); matcher.set(matchers_list[match_type],matcher_params); @@ -96,7 +96,7 @@ int main(int argc, char *argv[]) std::cout << std::endl << "Which MATCHER do you want to test?[default: " << matchers_search_list[match_search_type] << "]"; - match_search_type = readFromUser(match_search_type); +// match_search_type = readFromUser(match_search_type); matcher.setSearchType(matchers_search_list[match_search_type],matcher_search_params); @@ -137,13 +137,17 @@ int main(int argc, char *argv[]) cv::Mat descriptors; descriptors = descriptor.getDescriptor(frame,keypoints); -// // Matcher -// if (nframe > 0) -// { -// std::vector<cv::DMatch> matches; -// matcher.match(keypoints,keypoints_old,matches); -// } -// keypoints_old = keypoints; + // Matcher + if (nframe > 1) + { + std::vector<cv::DMatch> matches; + matcher.match(keypoints,keypoints_old,matches); + } + + // update old keypoints + keypoints_old.clear(); + for (unsigned int ii = 0; ii < keypoints.size(); ++ii) + keypoints_old.push_back(keypoints[ii]); // Show frame with features detector.drawKeyFeatures(frame, keypoints); diff --git a/src/feature_descriptor/feature_descriptor.cpp b/src/feature_descriptor/feature_descriptor.cpp index 86c6fab37ca702f7e974c363513b264ddb79dd4e..aca2e4049f7074d7d7f5a5fb420f6fc8e429c284 100644 --- a/src/feature_descriptor/feature_descriptor.cpp +++ b/src/feature_descriptor/feature_descriptor.cpp @@ -113,7 +113,8 @@ cv::Mat CFeature_Descriptor::getDescriptor(const cv::Mat& _image, KeyPointVector cv::Mat descriptors; clock_t tStart = clock(); - feature_descriptor_->compute(_image, _kpts, descriptors); + if (!_kpts.empty()) + feature_descriptor_->compute(_image, _kpts, descriptors); comp_time_ = (double)(clock() - tStart) / CLOCKS_PER_SEC; return descriptors; diff --git a/src/feature_matcher/feature_matcher.cpp b/src/feature_matcher/feature_matcher.cpp index 32b15f1715744e0141be3bb8f7821cf4a7ee2d4f..a0a7e997f0818cecb36891d230d5fafc64f92949 100644 --- a/src/feature_matcher/feature_matcher.cpp +++ b/src/feature_matcher/feature_matcher.cpp @@ -112,6 +112,7 @@ bool CFeature_Matcher::init(const std::string& _type, const CMatcher_Params& _pa // TODO: Match features and process matches (e.g. https://github.com/kipr/opencv/blob/master/samples/cpp/detector_descriptor_matcher_evaluation.cpp) void CFeature_Matcher::match(const KeyPointVector& _kpts1, const KeyPointVector& _kpts2, std::vector<cv::DMatch>& matches) { + std::cout << __LINE__ << std::endl; if (!is_init_) std::cerr << "[CFeature_Matcher::match]: Matcher non initialized." << std::endl; @@ -119,7 +120,9 @@ void CFeature_Matcher::match(const KeyPointVector& _kpts1, const KeyPointVector& { clock_t tStart = clock(); // TODO: use parameters related with the search type (match_search_params_) - feature_matcher_->match( _kpts1, _kpts2, matches); + std::cout << __LINE__ << " " << _kpts1.size() << " " << _kpts2.size() << std::endl; + if (!_kpts1.empty() && !_kpts2.empty()) + feature_matcher_->match( _kpts1, _kpts2, matches); comp_time_ = (double)(clock() - tStart) / CLOCKS_PER_SEC; } else @@ -136,16 +139,17 @@ void CFeature_Matcher::match(const KeyPointVector& _kpts1, const KeyPointVector& { clock_t tStart = clock(); // TODO: use parameters related with the search type (match_search_params_) - feature_matcher_->knnMatch(_kpts1, _kpts2, matches, 2); + if (!_kpts1.empty() && !_kpts2.empty()) + feature_matcher_->knnMatch(_kpts1, _kpts2, matches, 2); comp_time_ = (double)(clock() - tStart) / CLOCKS_PER_SEC; } else if (match_search_type_.compare(match_search_types_(2))==0) // radius match { clock_t tStart = clock(); // TODO: use parameters related with the search type (match_search_params_) - feature_matcher_->radiusMatch(_kpts1, _kpts2, matches, 2); + if (!_kpts1.empty() && !_kpts2.empty()) + feature_matcher_->radiusMatch(_kpts1, _kpts2, matches, 2); comp_time_ = (double)(clock() - tStart) / CLOCKS_PER_SEC; - } else std::cerr << "[CFeature_Matcher::match]: The selected matcher output is different than your object." << std::endl;