Ocean
Loading...
Searching...
No Matches
BullseyesDebugElements.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 META_OCEAN_CV_DETECTOR_BULLSEYES_BULLSEYES_DEBUG_ELEMENTS_H
9#define META_OCEAN_CV_DETECTOR_BULLSEYES_BULLSEYES_DEBUG_ELEMENTS_H
10
13
15#include "ocean/base/Frame.h"
16
17#include "ocean/math/Math.h"
18
19#include <vector>
20
21namespace Ocean
22{
23
24namespace CV
25{
26
27namespace Detector
28{
29
30namespace Bullseyes
31{
32
33/**
34 * This class implements debug elements for the bullseyes library.
35 * Debug elements allow to visualize results and intermediate steps from bullseye detection algorithms.
36 * @ingroup cvdetectorbullseyes
37 */
38class OCEAN_CV_DETECTOR_BULLSEYES_EXPORT BullseyesDebugElements final :
39 public DebugElements,
40 public Singleton<BullseyesDebugElements>
41{
43
44 public:
45
46 /// True, in case debugging is allowed and debugging code will be included into the binary; False, to disable debugging code.
47 static constexpr bool allowDebugging_ = true;
48
49 /**
50 * Definition of several debug elements.
51 */
52 enum ElementId : uint32_t
53 {
54 /// An invalid element id.
55 EI_INVALID = 0u,
56
57 /// BullseyeDetectorMono: Image visualizing valid segment sequences detected in rows.
59
60 /// BullseyeDetectorMono: Image visualizing bullseye candidates that passed neighborhood verification.
62
63 /// BullseyeDetectorMono: Image visualizing pixel validation during neighborhood checks.
65
66 /// BullseyeDetectorMono: Radial consistency Phase 1 - ray casting and transition detection.
68
69 /// BullseyeDetectorMono: Radial consistency Phase 2 - symmetry validation.
71
72 /// BullseyeDetectorMono: Radial consistency Phase 3 - intensity verification.
73 EI_RADIAL_CONSISTENCY_PHASE3
74 };
75
76 /**
77 * This class implements a scoped hierarchy.
78 * The hierarchy exists as long as this object exists.
79 */
81 {
82 public:
83
84 /**
85 * Creates a new scoped object and pushes the given hierarchy.
86 * @param hierarchy The hierarchy to be pushed, must be valid
87 */
88 inline ScopedHierarchy(const std::string& hierarchy);
89 };
90
91 /**
92 * Returns the hierarchy name for the left camera/frame.
93 * @return The hierarchy name "left"
94 */
95 static inline std::string hierarchyNameLeftFrame();
96
97 /**
98 * Returns the hierarchy name for the right camera/frame.
99 * @return The hierarchy name "right"
100 */
101 static inline std::string hierarchyNameRightFrame();
102
103 public:
104
105 /**
106 * Sets the current left and right camera frames for debug visualization.
107 * If any element ID is enabled, this function stores the frames for later use in drawing functions.
108 * This function must be called before detection so that draw functions (e.g., drawBullseyeCandidateInRow)
109 * can overlay debug information on the original frames. This is necessary because the detector may
110 * operate on pyramid layers with different resolutions than the original frames.
111 *
112 * Typical usage:
113 * @code
114 * // Before detection: store the original camera frames
115 * BullseyesDebugElements::get().setCameraFrames(leftFrame, rightFrame);
116 *
117 * // Run detection (draw functions are called internally with pyramid-layer coordinates)
118 * for (size_t cameraIndex : {0, 1})
119 * {
120 * const ScopedHierarchy scopedHierarchy(cameraIndex == 0 ? hierarchyNameLeftFrame() : hierarchyNameRightFrame());
121 * BullseyeDetectorMono::detectBullseyes(frames[cameraIndex], bullseyes);
122 * }
123 *
124 * // After detection: retrieve debug frames per hierarchy
125 * Frame debugLeft = BullseyesDebugElements::get().element(EI_DETECT_BULLSEYE_IN_ROW_VALID_SEQUENCE, {hierarchyNameLeftFrame()}, true);
126 * Frame debugRight = BullseyesDebugElements::get().element(EI_DETECT_BULLSEYE_IN_ROW_VALID_SEQUENCE, {hierarchyNameRightFrame()}, true);
127 * @endcode
128 *
129 * @param leftFrame The left camera frame (Y8 grayscale), will be copied if any element is active
130 * @param rightFrame The right camera frame (Y8 grayscale), will be copied if any element is active
131 */
132 void setCameraFrames(const Frame& leftFrame, const Frame& rightFrame);
133
134 /**
135 * Returns the current camera frame for the specified side.
136 * @param left True to get the left camera frame, false to get the right camera frame
137 * @return The camera frame, may be invalid if not set
138 */
139 Frame getCameraFrame(const bool left) const;
140
141 /**
142 * Draws a bullseye candidate detected in a row.
143 * The function visualizes the five alternating segments (black-white-black-white-black) that form a potential bullseye pattern.
144 * Uses the stored camera frame based on the current hierarchy (left/right).
145 * @param yRow The row index where the candidate was detected (in pyramid layer coordinates), with range [0, frame.height())
146 * @param segmentStart The x-coordinate where the first black segment starts (in pyramid layer coordinates), with range [0, frame.width())
147 * @param segment1Size The size of the first black segment in pixels (in pyramid layer coordinates), with range [1, infinity)
148 * @param segment2Size The size of the first white segment in pixels (in pyramid layer coordinates), with range [1, infinity)
149 * @param segment3Size The size of the center black segment (dot) in pixels (in pyramid layer coordinates), with range [1, infinity)
150 * @param segment4Size The size of the second white segment in pixels (in pyramid layer coordinates), with range [1, infinity)
151 * @param segment5Size The size of the second black segment in pixels (in pyramid layer coordinates), with range [1, infinity)
152 * @param scale Scale factor for coordinates, e.g., 2^i for pyramid layer i, with range [1, infinity)
153 * @sa setCameraFrames()
154 */
155 void drawBullseyeCandidateInRow(const unsigned int yRow, const unsigned int segmentStart, const unsigned int segment1Size, const unsigned int segment2Size, const unsigned int segment3Size, const unsigned int segment4Size, const unsigned int segment5Size, const Scalar scale = Scalar(1));
156
157 /**
158 * Draws a bullseye candidate that passed the neighborhood verification check.
159 * The function visualizes the center point and a circle with the given diameter.
160 * Uses the stored camera frame based on the current hierarchy (left/right).
161 * @param yCenter The y-coordinate of the bullseye center (in pyramid layer coordinates), with range [0, frame.height())
162 * @param xCenter The x-coordinate of the bullseye center (in pyramid layer coordinates), with range [0, frame.width())
163 * @param scale Scale factor for coordinates, e.g., 2^i for pyramid layer i, with range [1, infinity)
164 * @param diameter The diameter of the bullseye in pixels (in pyramid layer coordinates), with range [1, infinity)
165 * @sa setCameraFrames()
166 */
167 void drawCheckBullseyeInNeighborhood(const unsigned int yCenter, const unsigned int xCenter, const Scalar scale, const unsigned int diameter);
168
169 /**
170 * Draws a pixel validation point during neighborhood verification.
171 * The function visualizes individual pixel checks with color indicating validity.
172 * Uses the stored camera frame based on the current hierarchy (left/right).
173 * @param y The y-coordinate of the pixel (in pyramid layer coordinates), with range [0, frame.height())
174 * @param x The x-coordinate of the pixel (in pyramid layer coordinates), with range [0, frame.width())
175 * @param isInvalid True if the pixel failed validation (draws red), false if valid (draws green)
176 * @sa setCameraFrames()
177 */
178 void drawPixelValidation(const unsigned int y, const unsigned int x, const bool isInvalid);
179
180 /**
181 * Draws debug visualization for radial consistency Phase 1 - ray casting.
182 * Visualizes the transition points found on each diameter (positive and negative half-rays).
183 * Green points indicate valid transitions, red points indicate invalid/missing transitions.
184 * Uses the stored camera frame based on the current hierarchy (left/right).
185 * @param yCenter The y-coordinate of the bullseye center (in pyramid layer coordinates), with range [0, frame.height())
186 * @param xCenter The x-coordinate of the bullseye center (in pyramid layer coordinates), with range [0, frame.width())
187 * @param scale Scale factor for coordinates, e.g., 2^i for pyramid layer i, with range [1, infinity)
188 * @param diameters The diameter results from Phase 1 ray casting
189 * @param passed True if Phase 1 passed (enough valid diameters found)
190 * @sa setCameraFrames()
191 */
192 void drawRadialConsistencyPhase1(const unsigned int yCenter, const unsigned int xCenter, const Scalar scale, const Diameters& diameters, const bool passed);
193
194 /**
195 * Draws debug visualization for radial consistency Phase 2 - symmetry validation.
196 * Visualizes the symmetry between positive and negative half-rays of each diameter.
197 * Green = symmetric (passed), red = asymmetric (failed), gray = invalid diameter.
198 * Uses the stored camera frame based on the current hierarchy (left/right).
199 * @param yCenter The y-coordinate of the bullseye center (in pyramid layer coordinates), with range [0, frame.height())
200 * @param xCenter The x-coordinate of the bullseye center (in pyramid layer coordinates), with range [0, frame.width())
201 * @param scale Scale factor for coordinates, e.g., 2^i for pyramid layer i, with range [1, infinity)
202 * @param diameters The diameter results after Phase 2 symmetry validation
203 * @param passed True if Phase 2 passed (enough symmetric diameters)
204 * @sa setCameraFrames()
205 */
206 void drawRadialConsistencyPhase2(const unsigned int yCenter, const unsigned int xCenter, const Scalar scale, const Diameters& diameters, const bool passed);
207
208 /**
209 * Draws debug visualization for radial consistency Phase 3 - intensity verification.
210 * Visualizes the intensity check points and whether they passed verification.
211 * Green = intensity correct, red = intensity incorrect.
212 * Uses the stored camera frame based on the current hierarchy (left/right).
213 * @param yCenter The y-coordinate of the bullseye center (in pyramid layer coordinates), with range [0, frame.height())
214 * @param xCenter The x-coordinate of the bullseye center (in pyramid layer coordinates), with range [0, frame.width())
215 * @param scale Scale factor for coordinates, e.g., 2^i for pyramid layer i, with range [1, infinity)
216 * @param diameters The diameter results after Phase 3 intensity verification
217 * @param passed True if Phase 3 passed (enough intensity checks passed)
218 * @sa setCameraFrames()
219 */
220 void drawRadialConsistencyPhase3(const unsigned int yCenter, const unsigned int xCenter, const Scalar scale, const Diameters& diameters, const bool passed);
221
222 protected:
223
224 /// The stored left camera frame for debug visualization.
226
227 /// The stored right camera frame for debug visualization.
229};
230
232 ScopedHierarchyBase(get(), hierarchy)
233{
234 // Nothing to do here.
235}
236
238{
239 return "left";
240}
241
243{
244 return "right";
245}
246
247}
248
249}
250
251}
252
253}
254
255#endif // META_OCEAN_CV_DETECTOR_BULLSEYES_BULLSEYES_DEBUG_ELEMENTS_H
This class implements a scoped hierarchy.
Definition BullseyesDebugElements.h:81
ScopedHierarchy(const std::string &hierarchy)
Creates a new scoped object and pushes the given hierarchy.
Definition BullseyesDebugElements.h:231
This class implements debug elements for the bullseyes library.
Definition BullseyesDebugElements.h:41
void drawBullseyeCandidateInRow(const unsigned int yRow, const unsigned int segmentStart, const unsigned int segment1Size, const unsigned int segment2Size, const unsigned int segment3Size, const unsigned int segment4Size, const unsigned int segment5Size, const Scalar scale=Scalar(1))
Draws a bullseye candidate detected in a row.
void setCameraFrames(const Frame &leftFrame, const Frame &rightFrame)
Sets the current left and right camera frames for debug visualization.
void drawRadialConsistencyPhase3(const unsigned int yCenter, const unsigned int xCenter, const Scalar scale, const Diameters &diameters, const bool passed)
Draws debug visualization for radial consistency Phase 3 - intensity verification.
ElementId
Definition of several debug elements.
Definition BullseyesDebugElements.h:53
@ EI_DETECT_BULLSEYE_IN_ROW_VALID_SEQUENCE
BullseyeDetectorMono: Image visualizing valid segment sequences detected in rows.
Definition BullseyesDebugElements.h:58
@ EI_RADIAL_CONSISTENCY_PHASE1
BullseyeDetectorMono: Radial consistency Phase 1 - ray casting and transition detection.
Definition BullseyesDebugElements.h:67
@ EI_RADIAL_CONSISTENCY_PHASE2
BullseyeDetectorMono: Radial consistency Phase 2 - symmetry validation.
Definition BullseyesDebugElements.h:70
@ EI_CHECK_BULLSEYE_IN_NEIGHBORHOOD
BullseyeDetectorMono: Image visualizing bullseye candidates that passed neighborhood verification.
Definition BullseyesDebugElements.h:61
@ EI_PIXEL_VALIDATION
BullseyeDetectorMono: Image visualizing pixel validation during neighborhood checks.
Definition BullseyesDebugElements.h:64
void drawRadialConsistencyPhase2(const unsigned int yCenter, const unsigned int xCenter, const Scalar scale, const Diameters &diameters, const bool passed)
Draws debug visualization for radial consistency Phase 2 - symmetry validation.
void drawPixelValidation(const unsigned int y, const unsigned int x, const bool isInvalid)
Draws a pixel validation point during neighborhood verification.
static std::string hierarchyNameRightFrame()
Returns the hierarchy name for the right camera/frame.
Definition BullseyesDebugElements.h:242
Frame getCameraFrame(const bool left) const
Returns the current camera frame for the specified side.
static std::string hierarchyNameLeftFrame()
Returns the hierarchy name for the left camera/frame.
Definition BullseyesDebugElements.h:237
void drawRadialConsistencyPhase1(const unsigned int yCenter, const unsigned int xCenter, const Scalar scale, const Diameters &diameters, const bool passed)
Draws debug visualization for radial consistency Phase 1 - ray casting.
Frame leftCameraFrame_
The stored left camera frame for debug visualization.
Definition BullseyesDebugElements.h:225
Frame rightCameraFrame_
The stored right camera frame for debug visualization.
Definition BullseyesDebugElements.h:228
void drawCheckBullseyeInNeighborhood(const unsigned int yCenter, const unsigned int xCenter, const Scalar scale, const unsigned int diameter)
Draws a bullseye candidate that passed the neighborhood verification check.
This class implements a scoped hierarchy.
Definition DebugElements.h:37
This class implements the base class for a container for debug elements.
Definition DebugElements.h:29
This class implements Ocean's image class.
Definition Frame.h:1879
This template class is the base class for all singleton objects.
Definition Singleton.h:71
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< Diameter > Diameters
Definition of a vector holding diameters.
Definition Bullseye.h:124
The namespace covering the entire Ocean framework.
Definition Accessor.h:15