From 758cdee6cc2e48013a315ed6ef2ce8f1e42c32d6 Mon Sep 17 00:00:00 2001
From: asantamaria <asantamaria@iri.upc.edu>
Date: Wed, 2 Aug 2017 11:24:00 +0200
Subject: [PATCH] adde update of kp in example

---
 .../feature_detect_descript_match.cpp         | 26 +++++++++++--------
 src/feature_descriptor/feature_descriptor.cpp |  3 ++-
 src/feature_matcher/feature_matcher.cpp       | 12 ++++++---
 3 files changed, 25 insertions(+), 16 deletions(-)

diff --git a/src/examples/feature_detect_descript_match.cpp b/src/examples/feature_detect_descript_match.cpp
index 5b3b7eb..02658d1 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 86c6fab..aca2e40 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 32b15f1..a0a7e99 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;
-- 
GitLab