Register
Login
Resources
Docs Blog Datasets Glossary Case Studies Tutorials & Webinars
Product
Data Engine LLMs Platform Enterprise
Pricing Explore
Connect to our Discord channel

bounding_box.hpp 3.0 KB

You have to be logged in to leave a comment. Sign In
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
  1. #ifndef bounding_box_hpp
  2. #define bounding_box_hpp
  3. #include <vector>
  4. #include <opencv2/opencv.hpp>
  5. /// @Brief: A very small class implementing bounding box instead of using
  6. /// cv::Rect
  7. class BoundingBox {
  8. /**
  9. * @Brief: non-maxium suppression algorithm with the result averaged
  10. *
  11. * @param std::vector<BoundingBox>& Raw bounding box being processed
  12. * @param std::vector<BoundingBox>& Processed bounding box
  13. * @param float The threshold of overlapping
  14. */
  15. friend void nms_average(std::vector<BoundingBox>&,
  16. std::vector<BoundingBox>&, float);
  17. /**
  18. * @Brief: non-maxium suppression algorithm with the result maximized
  19. *
  20. * @param std::vector<BoundingBox>& Raw bounding box being processed
  21. * @param std::vector<BoundingBox>& Processed bounding box
  22. * @param float The threshold of overlapping
  23. */
  24. friend void nms_max(std::vector<BoundingBox>&,
  25. std::vector<BoundingBox>&, float);
  26. /**
  27. * @Brief: sort the bounding box by their probability with ">"
  28. *
  29. * @param BoundingBox& first bounding box
  30. * @param BoundingBox& second bounding box
  31. *
  32. * @return bool
  33. */
  34. friend bool sort_by_confidence_reverse(const BoundingBox&,
  35. const BoundingBox&);
  36. /**
  37. * @Brief: sort the bounding box by their size with "<"
  38. *
  39. * @param BoundingBox& first bounding box
  40. * @param BoundingBox& second bounding box
  41. *
  42. * @return bool
  43. */
  44. friend bool sort_by_size(const BoundingBox&,
  45. const BoundingBox&);
  46. public:
  47. BoundingBox(float x, float y, float width, float height, float prob): x(x), y(y), width(width), height(height), prob(prob) {};
  48. BoundingBox(BoundingBox&&) = default;
  49. BoundingBox(const BoundingBox&) = default;
  50. BoundingBox& operator=(const BoundingBox&) = default;
  51. BoundingBox& operator=(BoundingBox&&) = default;
  52. BoundingBox() = default;
  53. ~BoundingBox() = default;
  54. /**
  55. * @Brief: Change the bounding box to cv::Rect ignoring the prob
  56. */
  57. cv::Rect transformToCVRect() { return cv::Rect(x, y, width, height); };
  58. float getX() const { return x; };
  59. float getY() const { return y; };
  60. float getWidth() const { return width; };
  61. float getHeight() const { return height; };
  62. float getProb() const { return prob; };
  63. private:
  64. float area() const { return width * height; };
  65. float x;
  66. float y;
  67. float width;
  68. float height;
  69. float prob; /// The possibility of this area being a face
  70. };
  71. bool sort_by_confidence_reverse(const BoundingBox& a,
  72. const BoundingBox& b);
  73. bool sort_by_size(const BoundingBox&, const BoundingBox&);
  74. void nms_average(std::vector<BoundingBox>&,
  75. std::vector<BoundingBox>&, float);
  76. void nms_max(std::vector<BoundingBox>&,
  77. std::vector<BoundingBox>&, float);
  78. #endif /* bounding_box_hpp */
Tip!

Press p or to see the previous file or, n or to see the next file

Comments

Loading...