Ocean
cv/detector/Utilities.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_UTILITIES_H
9 #define META_OCEAN_CV_DETECTOR_UTILITIES_H
10 
12 
13 #include "ocean/base/Frame.h"
14 
16 
17 #include "ocean/math/FiniteLine2.h"
19 #include "ocean/math/Vector2.h"
20 
21 namespace Ocean
22 {
23 
24 namespace CV
25 {
26 
27 namespace Detector
28 {
29 
30 /**
31  * This class is a collection of detector-related utitility functions.
32  * @ingroup cvdetector
33  */
34 class OCEAN_CV_DETECTOR_EXPORT Utilities
35 {
36  public:
37 
38  /**
39  * Draws finite lines into an image.
40  * @param frame The image in which the L-shapes will be painted, must be valid
41  * @param finiteLines The finite lines that will be painted
42  * @param foregroundColor The foreground color in which the finite lines will be painted, must have as many elements as the image has channels, must be valid
43  * @param backgroundColor Optional background color, nullptr to avoid using a background color
44  */
45  static void paintLines(Frame& frame, const FiniteLines2& finiteLines, const unsigned char* foregroundColor, const unsigned char* backgroundColor = nullptr);
46 
47  /**
48  * Draws L-shapes into an image.
49  * @param frame The image in which the L-shapes will be painted, must be valid
50  * @param finiteLines The finite lines forming the L-shapes
51  * @param lShapes The L-shapes to be painted
52  * @param foregroundColor The foreground color in which the finite lines will be painted, must have as many elements as the image has channels, must be valid
53  * @param backgroundColor Optional background color, nullptr to avoid using a background color
54  */
55  static void paintLShapes(Frame& frame, const FiniteLines2& finiteLines, const ShapeDetector::LShapes& lShapes, const unsigned char* foregroundColor, const unsigned char* backgroundColor = nullptr);
56 
57  /**
58  * Draws L-shapes into an image.
59  * @param frame The image in which the L-shapes will be painted, must be valid
60  * @param lShapes The L-shapes to be painted
61  * @param length The length of the painted shapes e.g., the directions, in pixel, with range (0, infinity)
62  * @param foregroundColor The foreground color in which the finite lines will be painted, must have as many elements as the image has channels, must be valid
63  * @param backgroundColor Optional background color, nullptr to avoid using a background color
64  * @param offset Optional explicit offset to be added to each shape location before painting
65  */
66  static void paintLShapes(Frame& frame, const ShapeDetector::LShapes& lShapes, const Scalar length, const unsigned char* foregroundColor, const unsigned char* backgroundColor = nullptr, const Vector2& offset = Vector2(0, 0));
67 
68  /**
69  * Draws T-shapes into an image.
70  * @param frame The image in which the T-shapes will be painted, must be valid
71  * @param tShapes The T-shapes to be painted
72  * @param length The length of the painted shapes e.g., the directions, in pixel, with range (0, infinity)
73  * @param foregroundColor The foreground color in which the finite lines will be painted, must have as many elements as the image has channels, must be valid
74  * @param backgroundColor Optional background color, nullptr to avoid using a background color
75  * @param offset Optional explicit offset to be added to each shape location before painting
76  */
77  static void paintTShapes(Frame& frame, const ShapeDetector::TShapes& tShapes, const Scalar length, const unsigned char* foregroundColor, const unsigned char* backgroundColor = nullptr, const Vector2& offset = Vector2(0, 0));
78 
79  /**
80  * Draws X-shapes into an image.
81  * @param frame The image in which the X-shapes will be painted, must be valid
82  * @param xShapes The X-shapes to be painted
83  * @param length The length of the painted shapes e.g., the directions, in pixel, with range (0, infinity)
84  * @param foregroundColor The foreground color in which the finite lines will be painted, must have as many elements as the image has channels, must be valid
85  * @param backgroundColor Optional background color, nullptr to avoid using a background color
86  * @param offset Optional explicit offset to be added to each shape location before painting
87  */
88  static void paintXShapes(Frame& frame, const ShapeDetector::XShapes& xShapes, const Scalar length, const unsigned char* foregroundColor, const unsigned char* backgroundColor = nullptr, const Vector2& offset = Vector2(0, 0));
89 
90  /**
91  * Draws shapes into an image.
92  * @param frame The image in which the shapes will be painted, must be valid
93  * @param lShapes The L-shapes to be painted
94  * @param tShapes The T-shapes to be painted
95  * @param xShapes The X-shapes to be painted
96  * @param length The length of the painted shapes e.g., the directions, in pixel, with range (0, infinity)
97  * @param drawBackground True, to draw a background below the shapes
98  * @param offset Optional explicit offset to be added to each shape location before painting
99  * @param foregroundColor Optional explicit foreground color for all shapes, nullptr to use the default colors for individual shape types
100  */
101  static void paintShapes(Frame& frame, const ShapeDetector::LShapes& lShapes, const ShapeDetector::TShapes& tShapes, const ShapeDetector::XShapes& xShapes, const Scalar length, const bool drawBackground = false, const Vector2& offset = Vector2(0, 0), const uint8_t* foregroundColor = nullptr);
102 
103  /**
104  * Draws shapes into an image.
105  * @param frame The image in which the shapes will be painted, must be valid
106  * @param shapes The pointers to TwoLineShape object (eigher L-shapes, T-shapes, or X-shapes), must be valid if `size` >= 1
107  * @param size The number of provided shapes, with range [0, infinity)
108  * @param length The length of the painted shapes e.g., the directions, in pixel, with range (0, infinity)
109  * @param drawBackground True, to draw a background below the shapes
110  * @param offset Optional explicit offset to be added to each shape location before painting
111  * @param foregroundColor Optional explicit foreground color for all shapes, nullptr to use the default colors for individual shape types
112  */
113  static void paintShapes(Frame& frame, const ShapeDetector::TwoLineShape* const * shapes, size_t size, const Scalar length, const bool drawBackground = false, const Vector2& offset = Vector2(0, 0), const uint8_t* foregroundColor = nullptr);
114 
115  /**
116  * Draws rectangles into an image.
117  * @param frame The image in which the rectangles will be painted, must be valid
118  * @param lShapes The L-shapes forming the rectangles
119  * @param rectangles The rectangles to be painted
120  * @param foregroundColor The foreground color in which the finite lines will be painted, must have as many elements as the image has channels, must be valid
121  * @param backgroundColor Optional background color, nullptr to avoid using a background color
122  */
123  static void paintRectangles(Frame& frame, const ShapeDetector::LShapes& lShapes, const ShapeDetector::IndexedRectangles& rectangles, const unsigned char* foregroundColor, const unsigned char* backgroundColor = nullptr);
124 
125  /**
126  * Visualizes the alignment between two sets of shapes (reference shapes and candidate shapes).
127  * @param frame The frame in which the reference shapes have been determined, must be valid
128  * @param rectifiedWidth The width of the resulting rectified frame showing the alignment, in pixel, with range [1, infinity)
129  * @param rectifiedHeight The height of the resulting rectified frame showing the alignment, in pixel, with range [1, infinity)
130  * @param frame_H_rectified The homography between rectified image and given frame
131  * @param shapeReferences The reference shapes to be painted
132  * @param shapeCandidates The candidate shapes to be painted
133  * @param referenceShapesOffset The optional explicit offset for each reference shape before it will be painted
134  * @param candidateShapesOffset The optional explicit offset for each candidate shape before it will be painted
135  * @return The resulting rectified frame showing the alignment between both sets of shapes
136  */
137  static Frame visualizeShapeAlignment(const Frame& frame, unsigned int rectifiedWidth, unsigned int rectifiedHeight, const SquareMatrix3& frame_H_rectified, const std::vector<const ShapeDetector::TwoLineShape*>& shapeReferences, const std::vector<const ShapeDetector::TwoLineShape*>& shapeCandidates, const Vector2& referenceShapesOffset = Vector2(0, 0), const Vector2& candidateShapesOffset = Vector2(0, 0));
138 };
139 
140 } // namespace Detector
141 
142 } // namespace CV
143 
144 } // namespace Ocean
145 
146 #endif // META_OCEAN_CV_DETECTOR_UTILITIES_H
This class implements the base class for all shapes based on two lines.
Definition: ShapeDetector.h:44
std::vector< LShape > LShapes
Definition of a vector holding L-shape objects.
Definition: ShapeDetector.h:369
std::vector< TShape > TShapes
Definition of a vector holding T-shape objects.
Definition: ShapeDetector.h:374
std::vector< XShape > XShapes
Definition of a vector holding X-shape objects.
Definition: ShapeDetector.h:379
std::vector< IndexedRectangle > IndexedRectangles
Definition of a vector holding rectangles.
Definition: ShapeDetector.h:389
This class is a collection of detector-related utitility functions.
Definition: cv/detector/Utilities.h:35
static void paintShapes(Frame &frame, const ShapeDetector::LShapes &lShapes, const ShapeDetector::TShapes &tShapes, const ShapeDetector::XShapes &xShapes, const Scalar length, const bool drawBackground=false, const Vector2 &offset=Vector2(0, 0), const uint8_t *foregroundColor=nullptr)
Draws shapes into an image.
static void paintTShapes(Frame &frame, const ShapeDetector::TShapes &tShapes, const Scalar length, const unsigned char *foregroundColor, const unsigned char *backgroundColor=nullptr, const Vector2 &offset=Vector2(0, 0))
Draws T-shapes into an image.
static void paintLines(Frame &frame, const FiniteLines2 &finiteLines, const unsigned char *foregroundColor, const unsigned char *backgroundColor=nullptr)
Draws finite lines into an image.
static void paintXShapes(Frame &frame, const ShapeDetector::XShapes &xShapes, const Scalar length, const unsigned char *foregroundColor, const unsigned char *backgroundColor=nullptr, const Vector2 &offset=Vector2(0, 0))
Draws X-shapes into an image.
static void paintLShapes(Frame &frame, const FiniteLines2 &finiteLines, const ShapeDetector::LShapes &lShapes, const unsigned char *foregroundColor, const unsigned char *backgroundColor=nullptr)
Draws L-shapes into an image.
static void paintShapes(Frame &frame, const ShapeDetector::TwoLineShape *const *shapes, size_t size, const Scalar length, const bool drawBackground=false, const Vector2 &offset=Vector2(0, 0), const uint8_t *foregroundColor=nullptr)
Draws shapes into an image.
static Frame visualizeShapeAlignment(const Frame &frame, unsigned int rectifiedWidth, unsigned int rectifiedHeight, const SquareMatrix3 &frame_H_rectified, const std::vector< const ShapeDetector::TwoLineShape * > &shapeReferences, const std::vector< const ShapeDetector::TwoLineShape * > &shapeCandidates, const Vector2 &referenceShapesOffset=Vector2(0, 0), const Vector2 &candidateShapesOffset=Vector2(0, 0))
Visualizes the alignment between two sets of shapes (reference shapes and candidate shapes).
static void paintLShapes(Frame &frame, const ShapeDetector::LShapes &lShapes, const Scalar length, const unsigned char *foregroundColor, const unsigned char *backgroundColor=nullptr, const Vector2 &offset=Vector2(0, 0))
Draws L-shapes into an image.
static void paintRectangles(Frame &frame, const ShapeDetector::LShapes &lShapes, const ShapeDetector::IndexedRectangles &rectangles, const unsigned char *foregroundColor, const unsigned char *backgroundColor=nullptr)
Draws rectangles into an image.
This class implements Ocean's image class.
Definition: Frame.h:1760
float Scalar
Definition of a scalar type.
Definition: Math.h:128
std::vector< FiniteLine2 > FiniteLines2
Definition of a vector holding FiniteLine2 objects.
Definition: FiniteLine2.h:57
VectorT2< Scalar > Vector2
Definition of a 2D vector.
Definition: Vector2.h:21
The namespace covering the entire Ocean framework.
Definition: Accessor.h:15