From f0c1f68606f1e448be12821baf9f8963ed84764c Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Joan=20Sol=C3=A0?= <jsola@iri.upc.edu>
Date: Thu, 17 May 2018 10:19:17 +0200
Subject: [PATCH] Add average computing times

---
 src/examples/fundamental_matrix.cpp       | 35 +++++++++++++++++++++--
 src/examples/yaml/fundamental_matrix.yaml |  6 ++--
 2 files changed, 35 insertions(+), 6 deletions(-)

diff --git a/src/examples/fundamental_matrix.cpp b/src/examples/fundamental_matrix.cpp
index 179874a..2810b28 100644
--- a/src/examples/fundamental_matrix.cpp
+++ b/src/examples/fundamental_matrix.cpp
@@ -153,6 +153,11 @@ int main(int argc, char** argv)
     KeyPointVector keypoints_1 = det_ptr->detect(image_buffer.back());
     cv::Mat descriptors_1 = des_ptr->getDescriptor( image_buffer.back(), keypoints_1);
 
+    clock_t tStart, tDet, tDesc, tMatch, tFilter, tFund;
+    double t_det(0), t_desc(0), t_match(0), t_filter(0), t_fund(0);
+    const int CLOCKS_PER_MSEC = (CLOCKS_PER_SEC/1000);
+
+    int n_iter = 0;
     while(1)
     {
     	capture >> img;
@@ -167,15 +172,22 @@ int main(int argc, char** argv)
         DMatchVector good_matches, inlier_matches;
         PointVector inliers_1, inliers_2;
 
+
+        tStart = clock();
+
         // detect and describe in new image
         KeyPointVector keypoints_2 = det_ptr->detect(img);
 
+        tDet = clock();
+
         if (keypoints_2.size()>0)
         {
         	image_buffer.add(img);
 
         	cv::Mat descriptors_2 = des_ptr->getDescriptor( image_buffer.back(), keypoints_2);
 
+            tDesc = clock();
+
         	unsigned int max_dist = 0;
         	unsigned int min_dist = 512;
 
@@ -185,6 +197,8 @@ int main(int argc, char** argv)
         		//-- Step 3: Matching descriptor vectors using FLANN matcher
         		mat_ptr->match(descriptors_1,descriptors_2,des_ptr->getSize(),matches);
 
+                tMatch = clock();
+
         		//-- Quick calculation of max and min distances between keypoints
         		for (int ii = 0; ii < descriptors_1.rows; ii++)
         		{
@@ -215,13 +229,17 @@ int main(int argc, char** argv)
         		}
         	}
 
+            tFilter = clock();
+
+
         	// Compute the Fundamental matrix F and discard outliers through ransac in one go
         	if (good_matches.size() > 20) // Minimum is 8 points, but we need more for robustness
         	{
         		// find fundamental matrix using RANSAC, return set of inliers as bool vector
-        		cv::Mat F = findFundamentalMat(matched_1, matched_2, cv::FM_RANSAC, 3.0, 0.98, inliers_bool);
+        		cv::Mat F = findFundamentalMat(matched_1, matched_2, cv::FM_RANSAC, 2.0, 0.98, inliers_bool);
+
 
-        		std::cout << "F = " << F << std::endl;
+                std::cout << "F = " << F << std::endl;
 
         		// Recover the inlier matches
         		for (unsigned int ii = 0; ii < good_matches.size(); ii++)
@@ -229,11 +247,22 @@ int main(int argc, char** argv)
         				inlier_matches.push_back(good_matches[ii]);
         	}
 
-        	std::cout << "Matches: initial " << matches.size() << " | good " << good_matches.size() << " | inliers "
+            tFund = clock();
+
+            std::cout << "Matches: initial " << matches.size() << " | good " << good_matches.size() << " | inliers "
         			<< inlier_matches.size() << std::endl;
 
         	std::cout << "kp1: " << keypoints_1.size() << " kp2: " << keypoints_2.size() << " inliers:" << inlier_matches.size() << std::endl;
 
+        	n_iter ++;
+        	t_det       += double(   tDet - tStart )/CLOCKS_PER_MSEC;
+        	t_desc      += double(  tDesc - tDet   )/CLOCKS_PER_MSEC;
+        	t_match     += double( tMatch - tDesc  )/CLOCKS_PER_MSEC;
+        	t_filter    += double(tFilter - tMatch )/CLOCKS_PER_MSEC;
+        	t_fund      += double(  tFund - tFilter)/CLOCKS_PER_MSEC;
+
+        	std::cout << "det: " << t_det/n_iter << "ms - desc: " << t_desc/n_iter << "ms - match: " << t_match/n_iter << "ms - filter: " << t_filter/n_iter << "ms - fund: " << t_fund/n_iter << "ms" << std::endl;
+
             std::cout << "+++++++++++++++" << std::endl;
 
         	// Draw RANSAC inliers
diff --git a/src/examples/yaml/fundamental_matrix.yaml b/src/examples/yaml/fundamental_matrix.yaml
index da5949a..b2e0977 100644
--- a/src/examples/yaml/fundamental_matrix.yaml
+++ b/src/examples/yaml/fundamental_matrix.yaml
@@ -1,12 +1,12 @@
 detector:
   type: "AGAST"         
-  threshold: 10
+  threshold: 8
   nonmaxSuppression: true
-  detection type: 3         #  AGAST_5_8=0, AGAST_7_12d=1, AGAST_7_12s=2, OAST_9_16=3, THRESHOLD=10000, NONMAX_SUPPRESSION=10001
+  detection type: 0         #  AGAST_5_8=0, AGAST_7_12d=1, AGAST_7_12s=2, OAST_9_16=3, THRESHOLD=10000, NONMAX_SUPPRESSION=10001
   
 descriptor:
   type: "BRIEF"
-  bytes: 32
+  bytes: 16
   use_orientation: false     
   
 matcher:
-- 
GitLab