PedestrainCounting
Geometry.h
1 
4 #ifndef GEOMETRY_HEADER
5 #define GEOMETRY_HEADER
6 
7 #define ONEOVERSQRT2PI 0.39894228f
8 
9 #include "GlobalHeader.h"
10 
11 class Rect;
12 class Point2D;
13 
14 class Size {
15 public:
16 
17  Size(int w = 0, int h = 0);
18 
19  int width, height;
20  int area;
21 
22  Size operator=(const Rect &r);
23  Size operator*(float f);
24  bool operator==(const Size &other) const;
25 
26  inline explicit operator cv::Size() const {
27  return cv::Size(width, height);
28  }
29 
30  bool IsIn(const Rect &rect) const;
31  bool IsIn(int upper, int left, int width, int height) const;
32 };
33 
34 class Rect {
35 public:
36  Rect(int u = 0, int l = 0, int w = 0, int h = 0)
37  : upper(u), left(l), width(w), height(h) {}
38 
39  int upper;
40  int left;
41  int height;
42  int width;
43 
44  // Shift this rectangle by an offset.
45  Rect operator+(const Point2D &offset) const;
46 
47  bool IsOverlap(const Rect &other) const;
48 
52  inline bool IsIn(const Rect &other) const {
53  if (other.upper > upper && other.left > left &&
54  other.upper + other.height < upper + height &&
55  other.left + other.width < left + width) {
56  return true;
57  }
58  else {
59  return false;
60  }
61  }
62 
63  // Explicit conversion.
64  explicit operator cv::Rect() const;
65 
66  explicit operator Size() const;
67 };
68 
69 class Point2D {
70 public:
71  Point2D(int r = 0, int c = 0);
72 
73  Point2D &operator=(const Rect &r);
74 
75  inline float SquaredDistance(const Point2D &other) const {
76  return (float)((row - other.row) * (row - other.row) + (col - other.col) * (col - other.col));
77  }
78 
79  inline float Distance(const Point2D &other) const {
80  return sqrtf(SquaredDistance(other));
81  }
82 
83  inline float SquaredLength() const {
84  return (float)(row * row + col * col);
85  }
86 
87  inline float Length() const {
88  return sqrtf(SquaredLength());
89  }
90 
91  inline Point2D operator-(const Point2D &other) const {
92  return Point2D(row - other.row, col - other.col);
93  }
94 
95  inline float operator*(const Point2D &other) const {
96  return (float)(row * other.row + col * other.col);
97  }
98 
99  inline Point2D operator*(float scale) const {
100  return Point2D(row * scale, col * scale);
101  }
102 
107  inline float ProjectResidual(const Point2D &other) const {
108  float dot = (*this) * other;
109  return (other - (*this)*(dot / SquaredLength())).Length();
110  }
111 
112  int row, col;
113 };
114 
115 inline float GetGaussianProb(float mean, float sigma, float value) {
116  float invSimga = 1.0f / sigma;
117  return ONEOVERSQRT2PI * invSimga * expf(-0.5f * powf((value - mean) * invSimga, 2.0f));
118 }
119 
120 #endif
Definition: Geometry.h:34
bool IsIn(const Rect &other) const
Definition: Geometry.h:52
Definition: Geometry.h:14
float ProjectResidual(const Point2D &other) const
Definition: Geometry.h:107
Definition: ImageDetector.h:16
Definition: Geometry.h:69