utils.h 2.0 KB

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