Ocean
FeatureDetector.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_FEATURE_DETECTOR_H
9 #define META_OCEAN_CV_DETECTOR_FEATURE_DETECTOR_H
10 
12 
13 #include "ocean/base/Frame.h"
14 #include "ocean/base/Worker.h"
15 
17 #include "ocean/cv/SubRegion.h"
18 
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 provides an abstraction for visual features and strong feature points.
32  * @ingroup cvdetector
33  */
34 class OCEAN_CV_DETECTOR_EXPORT FeatureDetector
35 {
36  protected:
37 
38  /**
39  * This class implements a vector extension holding an additional intensity parameter.
40  */
41  class IntensityVector2 : public Vector2
42  {
43  public:
44 
45  /**
46  * Creates a new intensity vector object with undefined vector elements.
47  * Beware: The elemtns are neither zero nor a specific value!
48  * @see VectorT2::VectorT2()
49  */
50  inline IntensityVector2();
51 
52  /**
53  * Creates a new intensity vector by the given postion and intensity value.
54  * @param position Vector position
55  * @param intensity Vector intensity
56  */
57  inline IntensityVector2(const Vector2& position, const int intensity);
58 
59  /**
60  * Returns the intensity value of this object.
61  * @return Intensity value
62  */
63  inline int intensity() const;
64 
65  /**
66  * Compares two intensity objects.
67  * @param object Second object to compare
68  * @return True, if the intensity of the left object is higher than the intensity of the right object
69  */
70  inline bool operator<(const IntensityVector2& object) const;
71 
72  private:
73 
74  /// Intensity value.
76  };
77 
78  /**
79  * Definition of a vector holding intensity vector objects.
80  */
81  typedef std::vector<IntensityVector2> IntensityVectors2;
82 
83  public:
84 
85  /**
86  * Determines the points in an 8bit grayscale image with highest Harris corner response votes.
87  * @param yFrame The 8bit grayscale frame in which the Harris corner respondes have to be determined, must be valid
88  * @param width The width of the frame in pixel, with range [5, infinity)
89  * @param height The height of the frame in pixel, with range [5, infinity)
90  * @param yFramePaddingElements The number of padding elements at the end of each row of yFrame, in elements, with range [0, infinity)
91  * @param positions Given 2D positions inside the frame that have to be ordered according their response intensities
92  * @param maximalPoints Number of maximal points that have to be returned
93  * @param minSqrDistance Minimal squared distance between the points to be accepted
94  * @param harrisThreshold Minimal threshold for all Harris responses (points below this threshold will be skipped)
95  * @param worker Optional worker object to distribute the computation
96  * @return The resulting feature points
97  */
98  static Vectors2 filterStrongHarrisPoints(const uint8_t* yFrame, const unsigned int width, const unsigned int height, const unsigned int yFramePaddingElements, const Vectors2& positions, const unsigned int maximalPoints, const Scalar minSqrDistance, const int harrisThreshold = 0, Worker* worker = nullptr);
99 
100  /**
101  * Determines strong feature points in a given image, optional a sub-region can be specified in that the points are detected.
102  * @param yFrame The frame in which the feature points are detected, must have pixel format FORMAT_Y, must be valid
103  * @param subRegion Optional sub-region specifying a small image area in that the points are detected, an invalid sub-region to use the entire frame
104  * @param horizontalBins Optional horizontal bins that can be used to distribute the tracked points into array bins (in each bin there will be at most one point)
105  * @param verticalBins Optional vertical bins that can be used to distribute the tracked points into array bins (in each bin there will be at most one point)
106  * @param strength Minimal aiming strength parameter of the tracked feature points, this value will be weakened if too less feature points can be detected
107  * @param worker Optional worker object to distribute the computation
108  * @param strengths Optional resulting strength values individual for each point
109  * @return The resulting feature points, feature points with high strength value first
110  */
111  static inline Vectors2 determineHarrisPoints(const Frame& yFrame, const SubRegion& subRegion = SubRegion(), const unsigned int horizontalBins = 0u, const unsigned int verticalBins = 0u, const unsigned int strength = 30u, Worker* worker = nullptr, std::vector<int>* strengths = nullptr);
112 
113  /**
114  * Determines strong feature points in a given image, optional a sub-region can be specified in that the points are detected.
115  * @param yFrame The 8 bit grayscale frame (Y8 pixel format) in which the feature points are detected, must be valid
116  * @param width The width of the given frame in pixel, with range [7, infinity)
117  * @param height The height of the given frame in pixel, with range [7, infinity)
118  * @param yFramePaddingElements The number of padding elements at the end of each row of yFrame, in elements, with range [0, infinity)
119  * @param subRegion Optional sub-region specifying a small image area in that the points are detected
120  * @param horizontalBins Optional horizontal bins that can be used to distribute the tracked points into array bins (in each bin there will be at most one point)
121  * @param verticalBins Optional vertical bins that can be used to distribute the tracked points into array bins (in each bin there will be at most one point)
122  * @param strength Minimal aiming strength parameter of the tracked feature points, this value will be weakened if too less feature points can be detected
123  * @param worker Optional worker object to distribute the computation
124  * @param strengths Optional resulting strength values individual for each point
125  * @return The resulting feature points, feature points with high strength value first
126  */
127  static Vectors2 determineHarrisPoints(const uint8_t* yFrame, const unsigned int width, const unsigned int height, const unsigned int yFramePaddingElements, const SubRegion& subRegion, const unsigned int horizontalBins = 0u, const unsigned int verticalBins = 0u, const unsigned int strength = 30u, Worker* worker = nullptr, std::vector<int>* strengths = nullptr);
128 };
129 
131  Vector2(),
132  vectorIntensity(NumericT<int>::minValue())
133 {
134  // nothing to do here
135 }
136 
137 inline FeatureDetector::IntensityVector2::IntensityVector2(const Vector2& position, const int intensity) :
138  Vector2(position),
139  vectorIntensity(intensity)
140 {
141  // nothing to do here
142 }
143 
145 {
146  return vectorIntensity;
147 }
148 
150 {
151  return vectorIntensity > object.vectorIntensity;
152 }
153 
154 inline Vectors2 FeatureDetector::determineHarrisPoints(const Frame& yFrame, const SubRegion& subRegion, const unsigned int horizontalBins, const unsigned int verticalBins, const unsigned int strength, Worker* worker, std::vector<int>* strengths)
155 {
157  {
158  ocean_assert(false && "Invalid pixel format!");
159  return Vectors2();
160  }
161 
162  return determineHarrisPoints(yFrame.constdata<uint8_t>(), yFrame.width(), yFrame.height(), yFrame.paddingElements(), subRegion, horizontalBins, verticalBins, strength, worker, strengths);
163 }
164 
165 }
166 
167 }
168 
169 }
170 
171 #endif // META_OCEAN_CV_DETECTOR_FEATURE_DETECTOR_H
This class implements a vector extension holding an additional intensity parameter.
Definition: FeatureDetector.h:42
int vectorIntensity
Intensity value.
Definition: FeatureDetector.h:75
bool operator<(const IntensityVector2 &object) const
Compares two intensity objects.
Definition: FeatureDetector.h:149
IntensityVector2()
Creates a new intensity vector object with undefined vector elements.
Definition: FeatureDetector.h:130
int intensity() const
Returns the intensity value of this object.
Definition: FeatureDetector.h:144
This class provides an abstraction for visual features and strong feature points.
Definition: FeatureDetector.h:35
static Vectors2 determineHarrisPoints(const uint8_t *yFrame, const unsigned int width, const unsigned int height, const unsigned int yFramePaddingElements, const SubRegion &subRegion, const unsigned int horizontalBins=0u, const unsigned int verticalBins=0u, const unsigned int strength=30u, Worker *worker=nullptr, std::vector< int > *strengths=nullptr)
Determines strong feature points in a given image, optional a sub-region can be specified in that the...
static Vectors2 filterStrongHarrisPoints(const uint8_t *yFrame, const unsigned int width, const unsigned int height, const unsigned int yFramePaddingElements, const Vectors2 &positions, const unsigned int maximalPoints, const Scalar minSqrDistance, const int harrisThreshold=0, Worker *worker=nullptr)
Determines the points in an 8bit grayscale image with highest Harris corner response votes.
std::vector< IntensityVector2 > IntensityVectors2
Definition of a vector holding intensity vector objects.
Definition: FeatureDetector.h:81
static Vectors2 determineHarrisPoints(const Frame &yFrame, const SubRegion &subRegion=SubRegion(), const unsigned int horizontalBins=0u, const unsigned int verticalBins=0u, const unsigned int strength=30u, Worker *worker=nullptr, std::vector< int > *strengths=nullptr)
Determines strong feature points in a given image, optional a sub-region can be specified in that the...
Definition: FeatureDetector.h:154
This class implement a sub-region either defined by 2D triangles or defined by a binary mask.
Definition: SubRegion.h:32
This class implements Ocean's image class.
Definition: Frame.h:1760
const T * constdata(const unsigned int planeIndex=0u) const
Returns a pointer to the read-only pixel data of a specific plane.
Definition: Frame.h:4136
unsigned int paddingElements(const unsigned int planeIndex=0u) const
Returns the optional number of padding elements at the end of each row for a specific plane.
Definition: Frame.h:4010
@ FORMAT_Y8
Pixel format for grayscale images with byte order Y and 8 bits per pixel.
Definition: Frame.h:594
unsigned int width() const
Returns the width of the frame format in pixel.
Definition: Frame.h:3111
unsigned int height() const
Returns the height of the frame in pixel.
Definition: Frame.h:3116
bool isPixelFormatCompatible(const PixelFormat pixelFormat) const
Returns whether the pixel format of this frame type is compatible with a given pixel format.
Definition: Frame.h:3166
This class provides basic numeric functionalities.
Definition: Numeric.h:57
This class implements a worker able to distribute function calls over different threads.
Definition: Worker.h:33
float Scalar
Definition of a scalar type.
Definition: Math.h:128
std::vector< Vector2 > Vectors2
Definition of a vector holding Vector2 objects.
Definition: Vector2.h:64
The namespace covering the entire Ocean framework.
Definition: Accessor.h:15