Skip to content

Commit f6deaf5

Browse files
committed
tracking tutorial: add fps to stats
1 parent a835517 commit f6deaf5

File tree

3 files changed

+17
-5
lines changed

3 files changed

+17
-5
lines changed

samples/cpp/tutorial_code/features2D/AKAZE_tracking/planar_tracking.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,11 @@ void Tracker::setFirstFrame(const Mat frame, vector<Point2f> bb, string title, S
6262

6363
Mat Tracker::process(const Mat frame, Stats& stats)
6464
{
65+
TickMeter tm;
6566
vector<KeyPoint> kp;
6667
Mat desc;
68+
69+
tm.start();
6770
detector->detectAndCompute(frame, noArray(), kp, desc);
6871
stats.keypoints = (int)kp.size();
6972

@@ -85,6 +88,8 @@ Mat Tracker::process(const Mat frame, Stats& stats)
8588
homography = findHomography(Points(matched1), Points(matched2),
8689
RANSAC, ransac_thresh, inlier_mask);
8790
}
91+
tm.stop();
92+
stats.fps = 1. / tm.getTimeSec();
8893

8994
if(matched1.size() < 4 || homography.empty()) {
9095
Mat res;

samples/cpp/tutorial_code/features2D/AKAZE_tracking/stats.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,21 @@ struct Stats
77
int inliers;
88
double ratio;
99
int keypoints;
10+
double fps;
1011

1112
Stats() : matches(0),
1213
inliers(0),
1314
ratio(0),
14-
keypoints(0)
15+
keypoints(0),
16+
fps(0.)
1517
{}
1618

1719
Stats& operator+=(const Stats& op) {
1820
matches += op.matches;
1921
inliers += op.inliers;
2022
ratio += op.ratio;
2123
keypoints += op.keypoints;
24+
fps += op.fps;
2225
return *this;
2326
}
2427
Stats& operator/=(int num)
@@ -27,6 +30,7 @@ struct Stats
2730
inliers /= num;
2831
ratio /= num;
2932
keypoints /= num;
33+
fps /= num;
3034
return *this;
3135
}
3236
};

samples/cpp/tutorial_code/features2D/AKAZE_tracking/utils.h

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,17 @@ void drawBoundingBox(Mat image, vector<Point2f> bb)
2525
void drawStatistics(Mat image, const Stats& stats)
2626
{
2727
static const int font = FONT_HERSHEY_PLAIN;
28-
stringstream str1, str2, str3;
28+
stringstream str1, str2, str3, str4;
2929

3030
str1 << "Matches: " << stats.matches;
3131
str2 << "Inliers: " << stats.inliers;
3232
str3 << "Inlier ratio: " << setprecision(2) << stats.ratio;
33+
str4 << "FPS: " << std::fixed << setprecision(2) << stats.fps;
3334

34-
putText(image, str1.str(), Point(0, image.rows - 90), font, 2, Scalar::all(255), 3);
35-
putText(image, str2.str(), Point(0, image.rows - 60), font, 2, Scalar::all(255), 3);
36-
putText(image, str3.str(), Point(0, image.rows - 30), font, 2, Scalar::all(255), 3);
35+
putText(image, str1.str(), Point(0, image.rows - 120), font, 2, Scalar::all(255), 3);
36+
putText(image, str2.str(), Point(0, image.rows - 90), font, 2, Scalar::all(255), 3);
37+
putText(image, str3.str(), Point(0, image.rows - 60), font, 2, Scalar::all(255), 3);
38+
putText(image, str4.str(), Point(0, image.rows - 30), font, 2, Scalar::all(255), 3);
3739
}
3840

3941
void printStatistics(string name, Stats stats)
@@ -45,6 +47,7 @@ void printStatistics(string name, Stats stats)
4547
cout << "Inliers " << stats.inliers << endl;
4648
cout << "Inlier ratio " << setprecision(2) << stats.ratio << endl;
4749
cout << "Keypoints " << stats.keypoints << endl;
50+
cout << "FPS " << std::fixed << setprecision(2) << stats.fps << endl;
4851
cout << endl;
4952
}
5053

0 commit comments

Comments
 (0)