1 #ifndef UTILS_H
2 #define UTILS_H
3
4 #include <opencv2/core.hpp>
5 #include <vector>
6 #include "stats.h"
7
8 using namespace std;
9 using namespace cv;
10
11 void drawBoundingBox(Mat image, vector<Point2f> bb);
12 void drawStatistics(Mat image, const Stats& stats);
13 void printStatistics(string name, Stats stats);
14 vector<Point2f> Points(vector<KeyPoint> keypoints);
15
drawBoundingBox(Mat image,vector<Point2f> bb)16 void drawBoundingBox(Mat image, vector<Point2f> bb)
17 {
18 for(unsigned i = 0; i < bb.size() - 1; i++) {
19 line(image, bb[i], bb[i + 1], Scalar(0, 0, 255), 2);
20 }
21 line(image, bb[bb.size() - 1], bb[0], Scalar(0, 0, 255), 2);
22 }
23
drawStatistics(Mat image,const Stats & stats)24 void drawStatistics(Mat image, const Stats& stats)
25 {
26 static const int font = FONT_HERSHEY_PLAIN;
27 stringstream str1, str2, str3;
28
29 str1 << "Matches: " << stats.matches;
30 str2 << "Inliers: " << stats.inliers;
31 str3 << "Inlier ratio: " << setprecision(2) << stats.ratio;
32
33 putText(image, str1.str(), Point(0, image.rows - 90), font, 2, Scalar::all(255), 3);
34 putText(image, str2.str(), Point(0, image.rows - 60), font, 2, Scalar::all(255), 3);
35 putText(image, str3.str(), Point(0, image.rows - 30), font, 2, Scalar::all(255), 3);
36 }
37
printStatistics(string name,Stats stats)38 void printStatistics(string name, Stats stats)
39 {
40 cout << name << endl;
41 cout << "----------" << endl;
42
43 cout << "Matches " << stats.matches << endl;
44 cout << "Inliers " << stats.inliers << endl;
45 cout << "Inlier ratio " << setprecision(2) << stats.ratio << endl;
46 cout << "Keypoints " << stats.keypoints << endl;
47 cout << endl;
48 }
49
Points(vector<KeyPoint> keypoints)50 vector<Point2f> Points(vector<KeyPoint> keypoints)
51 {
52 vector<Point2f> res;
53 for(unsigned i = 0; i < keypoints.size(); i++) {
54 res.push_back(keypoints[i].pt);
55 }
56 return res;
57 }
58
59 #endif // UTILS_H
60