Ocean
Loading...
Searching...
No Matches
Bullseye.h
Go to the documentation of this file.
1/*
2 * Copyright (c) Meta Platforms, Inc. and affiliates.
3 *
4 * This source code is licensed under the MIT license found in the
5 * LICENSE file in the root directory of this source tree.
6 */
7
8#ifndef OCEAN_CV_DETECTOR_BULLSEYES_BULLSEYE_H
9#define OCEAN_CV_DETECTOR_BULLSEYES_BULLSEYE_H
10
12
13#include "ocean/math/Numeric.h"
14#include "ocean/math/Vector2.h"
15
16#include <array>
17
18namespace Ocean
19{
20
21namespace CV
22{
23
24namespace Detector
25{
26
27namespace Bullseyes
28{
29
30/**
31 * Structure to hold a single half-ray result from radial consistency checking.
32 * A half-ray extends from the center of a bullseye candidate in one direction.
33 */
34class OCEAN_CV_DETECTOR_BULLSEYES_EXPORT HalfRay
35{
36 public:
37
38 /// Array of 3 transition points along the half-ray: [0] B->W (center to first ring), [1] W->B (first to second ring), [2] B->W (second ring to background)
39 using TransitionPoints = std::array<Vector2, 3>;
40
41 public:
42
43 /// Default constructor.
44 HalfRay() = default;
45
46 /**
47 * Returns whether this half-ray found all 3 transition points.
48 * @return True if all 3 transition points are valid and angle is within range [0, 2*PI)
49 */
50 inline bool isValid() const;
51
52 /**
53 * Returns whether all intensity check points have the expected values.
54 * @return True if all 3 intensity checks passed (background/foreground validation)
55 */
56 inline bool areIntensitiesValid() const;
57
58 /**
59 * Returns an invalid transition point.
60 * @return Invalid transition point
61 */
62 static inline const Vector2& invalidTransitionPoint();
63
64 /**
65 * Returns an invalid array of transition points.
66 * @return Array of 3 invalid transition points
67 */
68 static inline const TransitionPoints& invalidTransitionPoints();
69
70 public:
71
72 /// Transition points for this half-ray
73 TransitionPoints transitionPoints = invalidTransitionPoints();
74
75 /// Points sampled for intensity validation: [0] between transitions 0-1 (white ring), [1] between transitions 1-2 (black ring), [2] beyond transition 2 (background)
76 Vector2 intensityCheckPoints[3];
77
78 /// Flags indicating whether each intensity check passed: [0] white ring, [1] black ring, [2] background
79 bool isIntensityValid[3] = {false, false, false};
80
81 /// Angle of this half-ray in radians
82 Scalar angle = Scalar(-1);
83};
84
85/// Definition of a vector holding half-rays.
86using HalfRays = std::vector<HalfRay>;
87
88/**
89 * Structure to hold diameter results (positive + negative half-rays).
90 * A diameter consists of two half-rays extending in opposite directions from the center.
91 */
92class OCEAN_CV_DETECTOR_BULLSEYES_EXPORT Diameter
93{
94 public:
95
96 /// Default constructor.
97 Diameter() = default;
98
99 /**
100 * Returns whether both half-rays found all 3 transition points.
101 * @return True if both half-rays are valid
102 */
103 inline bool areHalfRaysValid() const;
104
105 /**
106 * Returns whether all intensity checks passed in both half-rays.
107 * @return True if both positive and negative half-rays have valid intensities (background and foreground values match expectations)
108 */
109 inline bool areIntensitiesValid() const;
110
111 public:
112
113 /// True if distances match within symmetry tolerance
114 bool isSymmetryValid = false;
115
116 /// Positive direction half-ray (angle a)
118
119 /// Negative direction half-ray (angle a + PI)
121};
122
123/// Definition of a vector holding diameters.
124using Diameters = std::vector<Diameter>;
125
126/**
127 * Definition of a bullseye composed of a location and a radius.
128 * @ingroup cvdetectorbullseyes
129 */
130class OCEAN_CV_DETECTOR_BULLSEYES_EXPORT Bullseye
131{
132 public:
133
134 /**
135 * Creates an invalid bullseye object.
136 */
137 Bullseye() = default;
138
139 /**
140 * Creates a new bullseye object by a given position and radius.
141 * @param position The (center) position of the bullseye within the camera frame
142 * @param radius The radius of the bullseye in pixels, with range (0, infinity)
143 * @param grayThreshold Threshold that was used during the detection, range [1, 255]
144 * @param pyramidLayer The pyramid layer at which this bullseye was detected, with range [0, infinity)
145 */
146 Bullseye(const Vector2& position, const Scalar& radius, const unsigned int grayThreshold, const unsigned int pyramidLayer = 0u);
147
148 /**
149 * Creates a new bullseye object with diameter data from radial consistency checking.
150 * @param position The (center) position of the bullseye within the camera frame
151 * @param radius The radius of the bullseye in pixels, with range (0, infinity)
152 * @param grayThreshold Threshold that was used during the detection, range [1, 255]
153 * @param diameters The diameter data from radial consistency checking
154 * @param pyramidLayer The pyramid layer at which this bullseye was detected, with range [0, infinity)
155 */
156 Bullseye(const Vector2& position, const Scalar& radius, const unsigned int grayThreshold, Diameters&& diameters, const unsigned int pyramidLayer = 0u);
157
158 /**
159 * Returns whether this bullseye is valid.
160 * @return True, if so
161 */
162 bool isValid() const;
163
164 /**
165 * Returns the (center) position of the bullseye.
166 * @return The Bullseye's position within the camera frame
167 */
168 const Vector2& position() const;
169
170 /**
171 * Returns the radius of the bullseye.
172 * @return The Bullseye's radius, with range (0, infinity), 0 for an invalid object
173 */
174 Scalar radius() const;
175
176 /**
177 * Returns the threshold that was used for the detection of this bullseye
178 * @return The threshold value
179 */
180 unsigned int grayThreshold() const;
181
182 /**
183 * Returns the pyramid layer at which this bullseye was detected.
184 * @return The pyramid layer index, with range [0, infinity)
185 */
186 unsigned int pyramidLayer() const;
187
188 /**
189 * Returns whether this bullseye has diameter data from radial consistency checking.
190 * @return True if diameter data is available, false otherwise
191 */
192 bool hasDiameters() const;
193
194 /**
195 * Returns the diameter data from radial consistency checking.
196 * @return The diameters, empty if not available
197 */
198 const Diameters& diameters() const;
199
200 /**
201 * Returns a scaled copy of this bullseye.
202 * Scales position, radius, and all diameter data by the given factor.
203 * @param scaleFactor The scale factor to apply, with range (0, infinity)
204 * @return A new Bullseye with scaled coordinates
205 */
206 Bullseye scaled(const Scalar scaleFactor) const;
207
208 /**
209 * Returns an invalid bullseye position.
210 * @return Invalid bullseye position
211 */
213
214 /**
215 * Returns an invalid bullseye radius.
216 * @return Invalid bullseye radius
217 */
218 static constexpr Scalar invalidRadius();
219
220 /**
221 * Returns an invalid bullseye threshold.
222 * @return Invalid bullseye threshold
223 */
224 static constexpr unsigned int invalidGrayThreshold();
225
226 protected:
227
228 /// The (center) position of the bullseye within the camera frame.
229 Vector2 position_ = invalidPosition();
230
231 /// The radius of the bullseye in pixels, with range (0, infinity).
232 Scalar radius_ = invalidRadius();
233
234 /// The threshold that was used during the detection of this bullseye
235 unsigned int grayThreshold_ = invalidGrayThreshold();
236
237 /// The diameter data from radial consistency checking.
239
240 /// The pyramid layer at which this bullseye was detected, with range [0, infinity).
241 unsigned int pyramidLayer_ = 0u;
242};
243
244/// Definition of a vector holding bullseyes.
245using Bullseyes = std::vector<Bullseye>;
246
248{
249 return Scalar(-1);
250}
251
252constexpr unsigned int Bullseye::invalidGrayThreshold()
253{
254 return (unsigned int)(-1);
255}
256
258{
259 static const Vector2 invalidPoint(Numeric::minValue(), Numeric::minValue());
260 return invalidPoint;
261}
262
264{
266 return invalidPoints;
267}
268
269inline bool HalfRay::isValid() const
270{
271 for (const Vector2& transitionPoint : transitionPoints)
272 {
273 if (transitionPoint == invalidTransitionPoint())
274 {
275 return false;
276 }
277 }
278
279 if (angle < 0 || angle >= Numeric::pi2())
280 {
281 return false;
282 }
283
284 return true;
285}
286
288{
290}
291
292inline bool Diameter::areHalfRaysValid() const
293{
295}
296
301
302} // namespace Bullseyes
303
304} // namespace Detector
305
306} // namespace CV
307
308} // namespace Ocean
309
310#endif // OCEAN_CV_DETECTOR_BULLSEYES_BULLSEYE_H
Definition of a bullseye composed of a location and a radius.
Definition Bullseye.h:131
bool isValid() const
Returns whether this bullseye is valid.
static constexpr Scalar invalidRadius()
Returns an invalid bullseye radius.
Definition Bullseye.h:247
Bullseye()=default
Creates an invalid bullseye object.
Bullseye scaled(const Scalar scaleFactor) const
Returns a scaled copy of this bullseye.
Bullseye(const Vector2 &position, const Scalar &radius, const unsigned int grayThreshold, Diameters &&diameters, const unsigned int pyramidLayer=0u)
Creates a new bullseye object with diameter data from radial consistency checking.
Bullseye(const Vector2 &position, const Scalar &radius, const unsigned int grayThreshold, const unsigned int pyramidLayer=0u)
Creates a new bullseye object by a given position and radius.
const Diameters & diameters() const
Returns the diameter data from radial consistency checking.
Diameters diameters_
The diameter data from radial consistency checking.
Definition Bullseye.h:238
bool hasDiameters() const
Returns whether this bullseye has diameter data from radial consistency checking.
unsigned int pyramidLayer() const
Returns the pyramid layer at which this bullseye was detected.
static constexpr unsigned int invalidGrayThreshold()
Returns an invalid bullseye threshold.
Definition Bullseye.h:252
static Vector2 invalidPosition()
Returns an invalid bullseye position.
const Vector2 & position() const
Returns the (center) position of the bullseye.
Scalar radius() const
Returns the radius of the bullseye.
unsigned int grayThreshold() const
Returns the threshold that was used for the detection of this bullseye.
Structure to hold diameter results (positive + negative half-rays).
Definition Bullseye.h:93
Diameter()=default
Default constructor.
HalfRay halfRayNegative
Negative direction half-ray (angle a + PI)
Definition Bullseye.h:120
HalfRay halfRayPositive
Positive direction half-ray (angle a)
Definition Bullseye.h:117
bool areHalfRaysValid() const
Returns whether both half-rays found all 3 transition points.
Definition Bullseye.h:292
bool areIntensitiesValid() const
Returns whether all intensity checks passed in both half-rays.
Definition Bullseye.h:297
Structure to hold a single half-ray result from radial consistency checking.
Definition Bullseye.h:35
std::array< Vector2, 3 > TransitionPoints
Array of 3 transition points along the half-ray: [0] B->W (center to first ring), [1] W->B (first to ...
Definition Bullseye.h:39
bool isValid() const
Returns whether this half-ray found all 3 transition points.
Definition Bullseye.h:269
HalfRay()=default
Default constructor.
bool areIntensitiesValid() const
Returns whether all intensity check points have the expected values.
Definition Bullseye.h:287
static const Vector2 & invalidTransitionPoint()
Returns an invalid transition point.
Definition Bullseye.h:257
bool isIntensityValid[3]
Flags indicating whether each intensity check passed: [0] white ring, [1] black ring,...
Definition Bullseye.h:79
static const TransitionPoints & invalidTransitionPoints()
Returns an invalid array of transition points.
Definition Bullseye.h:263
TransitionPoints transitionPoints
Transition points for this half-ray.
Definition Bullseye.h:73
static constexpr T minValue()
Returns the min scalar value.
Definition Numeric.h:3259
static constexpr T pi2()
Returns 2*PI which is equivalent to 360 degree.
Definition Numeric.h:932
float Scalar
Definition of a scalar type.
Definition Math.h:129
std::vector< Bullseye > Bullseyes
Definition of a vector holding bullseyes.
Definition Bullseye.h:245
std::vector< HalfRay > HalfRays
Definition of a vector holding half-rays.
Definition Bullseye.h:86
std::vector< Diameter > Diameters
Definition of a vector holding diameters.
Definition Bullseye.h:124
The namespace covering the entire Ocean framework.
Definition Accessor.h:15