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