tracking tutorial: add fps to stats
authorJiri Horner <laeqten@gmail.com>
Tue, 22 Aug 2017 10:56:52 +0000 (12:56 +0200)
committerJiri Horner <laeqten@gmail.com>
Wed, 23 Aug 2017 08:40:17 +0000 (10:40 +0200)
samples/cpp/tutorial_code/features2D/AKAZE_tracking/planar_tracking.cpp
samples/cpp/tutorial_code/features2D/AKAZE_tracking/stats.h
samples/cpp/tutorial_code/features2D/AKAZE_tracking/utils.h

index e4673f8..1d83983 100755 (executable)
@@ -62,8 +62,11 @@ void Tracker::setFirstFrame(const Mat frame, vector<Point2f> bb, string title, S
 
 Mat Tracker::process(const Mat frame, Stats& stats)
 {
+    TickMeter tm;
     vector<KeyPoint> kp;
     Mat desc;
+
+    tm.start();
     detector->detectAndCompute(frame, noArray(), kp, desc);
     stats.keypoints = (int)kp.size();
 
@@ -85,6 +88,8 @@ Mat Tracker::process(const Mat frame, Stats& stats)
         homography = findHomography(Points(matched1), Points(matched2),
                                     RANSAC, ransac_thresh, inlier_mask);
     }
+    tm.stop();
+    stats.fps = 1. / tm.getTimeSec();
 
     if(matched1.size() < 4 || homography.empty()) {
         Mat res;
index 343b789..f5e0948 100644 (file)
@@ -7,11 +7,13 @@ struct Stats
     int inliers;
     double ratio;
     int keypoints;
+    double fps;
 
     Stats() : matches(0),
         inliers(0),
         ratio(0),
-        keypoints(0)
+        keypoints(0),
+        fps(0.)
     {}
 
     Stats& operator+=(const Stats& op) {
@@ -19,6 +21,7 @@ struct Stats
         inliers += op.inliers;
         ratio += op.ratio;
         keypoints += op.keypoints;
+        fps += op.fps;
         return *this;
     }
     Stats& operator/=(int num)
@@ -27,6 +30,7 @@ struct Stats
         inliers /= num;
         ratio /= num;
         keypoints /= num;
+        fps /= num;
         return *this;
     }
 };
index a3e9d7d..b3f3aa5 100644 (file)
@@ -25,15 +25,17 @@ void drawBoundingBox(Mat image, vector<Point2f> bb)
 void drawStatistics(Mat image, const Stats& stats)
 {
     static const int font = FONT_HERSHEY_PLAIN;
-    stringstream str1, str2, str3;
+    stringstream str1, str2, str3, str4;
 
     str1 << "Matches: " << stats.matches;
     str2 << "Inliers: " << stats.inliers;
     str3 << "Inlier ratio: " << setprecision(2) << stats.ratio;
+    str4 << "FPS: " << std::fixed << setprecision(2) << stats.fps;
 
-    putText(image, str1.str(), Point(0, image.rows - 90), font, 2, Scalar::all(255), 3);
-    putText(image, str2.str(), Point(0, image.rows - 60), font, 2, Scalar::all(255), 3);
-    putText(image, str3.str(), Point(0, image.rows - 30), font, 2, Scalar::all(255), 3);
+    putText(image, str1.str(), Point(0, image.rows - 120), font, 2, Scalar::all(255), 3);
+    putText(image, str2.str(), Point(0, image.rows - 90), font, 2, Scalar::all(255), 3);
+    putText(image, str3.str(), Point(0, image.rows - 60), font, 2, Scalar::all(255), 3);
+    putText(image, str4.str(), Point(0, image.rows - 30), font, 2, Scalar::all(255), 3);
 }
 
 void printStatistics(string name, Stats stats)
@@ -45,6 +47,7 @@ void printStatistics(string name, Stats stats)
     cout << "Inliers " << stats.inliers << endl;
     cout << "Inlier ratio " << setprecision(2) << stats.ratio << endl;
     cout << "Keypoints " << stats.keypoints << endl;
+    cout << "FPS " << std::fixed << setprecision(2) << stats.fps << endl;
     cout << endl;
 }