diff --git a/samples/cpp/tutorial_code/features2D/AKAZE_tracking/planar_tracking.cpp b/samples/cpp/tutorial_code/features2D/AKAZE_tracking/planar_tracking.cpp index e4673f82f5..1d83983536 100755 --- a/samples/cpp/tutorial_code/features2D/AKAZE_tracking/planar_tracking.cpp +++ b/samples/cpp/tutorial_code/features2D/AKAZE_tracking/planar_tracking.cpp @@ -62,8 +62,11 @@ void Tracker::setFirstFrame(const Mat frame, vector bb, string title, S Mat Tracker::process(const Mat frame, Stats& stats) { + TickMeter tm; vector 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; diff --git a/samples/cpp/tutorial_code/features2D/AKAZE_tracking/stats.h b/samples/cpp/tutorial_code/features2D/AKAZE_tracking/stats.h index 343b789ea3..f5e09480d3 100644 --- a/samples/cpp/tutorial_code/features2D/AKAZE_tracking/stats.h +++ b/samples/cpp/tutorial_code/features2D/AKAZE_tracking/stats.h @@ -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; } }; diff --git a/samples/cpp/tutorial_code/features2D/AKAZE_tracking/utils.h b/samples/cpp/tutorial_code/features2D/AKAZE_tracking/utils.h index a3e9d7dbde..b3f3aa5692 100644 --- a/samples/cpp/tutorial_code/features2D/AKAZE_tracking/utils.h +++ b/samples/cpp/tutorial_code/features2D/AKAZE_tracking/utils.h @@ -25,15 +25,17 @@ void drawBoundingBox(Mat image, vector 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; }