tracking tutorial: add fps to stats

pull/9444/head
Jiri Horner 7 years ago
parent a835517049
commit f6deaf5f2a
  1. 5
      samples/cpp/tutorial_code/features2D/AKAZE_tracking/planar_tracking.cpp
  2. 6
      samples/cpp/tutorial_code/features2D/AKAZE_tracking/stats.h
  3. 11
      samples/cpp/tutorial_code/features2D/AKAZE_tracking/utils.h

@ -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;

@ -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;
}
};

@ -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;
}

Loading…
Cancel
Save