Ocean
PointFeature.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_POINT_FEATURE_H
9 #define META_OCEAN_CV_DETECTOR_POINT_FEATURE_H
10 
13 
15 
16 #include "ocean/math/Vector2.h"
17 #include "ocean/math/Vector3.h"
18 
19 namespace Ocean
20 {
21 
22 namespace CV
23 {
24 
25 namespace Detector
26 {
27 
28 // Forward declaration.
29 class PointFeature;
30 
31 /**
32  * Definition of a vector holding point features.
33  * @ingroup cvdetector
34  */
35 typedef std::vector<PointFeature> PointFeatures;
36 
37 /**
38  * This class implements the base class for all computer vision features mainly basing on points.
39  * The feature observation is the 2D position the feature can observed e.g. on an image plane.<br>
40  * In contrast the feature position is the real 3D position of the feature.
41  * @ingroup cvdetector
42  */
43 class OCEAN_CV_DETECTOR_EXPORT PointFeature : public Feature
44 {
45  public:
46 
47  /**
48  * Definition of individual distortion states.
49  */
51  {
52  /// Invalid distortion state.
54  /// Unknown distortion state.
56  /// Distorted position.
58  /// Undistorted (distortion free) position.
59  DS_UNDISTORTED
60  };
61 
62  public:
63 
64  /**
65  * Creates a new feature object
66  */
67  inline PointFeature();
68 
69  /**
70  * Creates a new feature object by a given 2D observation point.
71  * @param observation Feature 2D observation position
72  * @param distortionState Distortion state of the 2D feature position
73  * @param strength Feature strength
74  */
75  inline explicit PointFeature(const Vector2& observation, const DistortionState distortionState = DS_UNKNOWN, const Scalar strength = 0);
76 
77  /**
78  * Creates a new feature object by a given position.
79  * @param position Feature 3D position
80  * @param strength Feature strength
81  */
82  inline explicit PointFeature(const Vector3& position, const Scalar strength = 0);
83 
84  /**
85  * Returns the 2D observation position of this feature e.g. inside a camera frame
86  * @return 2D feature observation position
87  */
88  inline const Vector2& observation() const;
89 
90  /**
91  * Returns the 3D position of this feature e.g. in the corresponding coordinate system
92  * @return 3D feature position
93  */
94  inline const Vector3& position() const;
95 
96  /**
97  * Returns the strength of this feature
98  * @return Feature strength
99  */
100  inline Scalar strength() const;
101 
102  /**
103  * Returns the distortion state of the feature point.
104  * @return Distortion state.
105  */
106  inline DistortionState distortionState() const;
107 
108  /**
109  * Sets or changes the 2D observation position of this feature.
110  * @param position 2D feature position to set
111  * @param distortionState Distortion state of the feature position
112  */
113  inline void setObservation(const Vector2& position, const DistortionState distortionState);
114 
115  /**
116  * Sets or changes the 3D position of this feature.
117  * @param position 3D feature position to set
118  */
119  inline void setPosition(const Vector3& position);
120 
121  /**
122  * Sets or changes the strength of this feature.
123  * @param strength Feature strength to set
124  */
125  inline void setStrength(const Scalar strength);
126 
127  /**
128  * Converts a point feature to a simple 2D image position.
129  * Thus, the 2D position is preserved only.
130  * @param feature The point feature to convert
131  * @return Resulting image point
132  */
133  static inline const Geometry::ImagePoint& feature2imagePoint(const PointFeature& feature);
134 
135  /**
136  * Returns whether two feature objects are equal.
137  * @param feature Right feature to test
138  * @return True, if so
139  */
140  inline bool operator==(const PointFeature& feature) const;
141 
142  /**
143  * Returns whether two feature objects are not equal.
144  * @param feature Right feature to test
145  * @return True, if so
146  */
147  inline bool operator!=(const PointFeature& feature) const;
148 
149  /**
150  * Returns whether the this feature has a higher strength than a second feature object.
151  * @param feature Second feature to compare
152  * @return True, if so
153  */
154  inline bool operator<(const PointFeature& feature) const;
155 
156  protected:
157 
158  /// 2D feature observation point.
160 
161  /// 3D feature position.
163 
164  /// Feature strength.
166 
167  /// Holds the distortion state of the observation position.
169 };
170 
172  Feature(),
173  featureObservation(0, 0),
174  featurePosition(0, 0, 0),
175  featureStrength(0)
176 {
177  // nothing to do here
178 }
179 
180 inline PointFeature::PointFeature(const Vector2& observation, const DistortionState distortionState, const Scalar strength) :
181  Feature(),
182  featureObservation(observation),
183  featurePosition(0, 0, 0),
184  featureStrength(strength),
185  featureDistortionState(distortionState)
186 {
187  // nothing to do here
188 }
189 
190 inline PointFeature::PointFeature(const Vector3& position, const Scalar strength) :
191  Feature(),
192  featureObservation(0, 0),
193  featurePosition(position),
194  featureStrength(strength),
195  featureDistortionState(DS_INVALID)
196 {
197  // nothing to do here
198 }
199 
200 inline const Vector2& PointFeature::observation() const
201 {
202  return featureObservation;
203 }
204 
205 inline const Vector3& PointFeature::position() const
206 {
207  return featurePosition;
208 }
209 
211 {
212  return featureStrength;
213 }
214 
216 {
217  return featureDistortionState;
218 }
219 
220 inline void PointFeature::setObservation(const Vector2& observation, const DistortionState distortionState)
221 {
224 }
225 
226 inline void PointFeature::setPosition(const Vector3& position)
227 {
229 }
230 
231 inline void PointFeature::setStrength(const Scalar strength)
232 {
234 }
235 
237 {
238  return feature.observation();
239 }
240 
241 inline bool PointFeature::operator==(const PointFeature& feature) const
242 {
244 }
245 
246 inline bool PointFeature::operator!=(const PointFeature& feature) const
247 {
248  return !(*this == feature);
249 }
250 
251 inline bool PointFeature::operator<(const PointFeature& feature) const
252 {
253  return featureStrength > feature.featureStrength;
254 }
255 
256 }
257 
258 }
259 
260 }
261 
262 #endif // META_OCEAN_CV_DETECTOR_POINT_FEATURE_H
This class implements the abstract base class for arbitrary computer vision features.
Definition: Feature.h:35
This class implements the base class for all computer vision features mainly basing on points.
Definition: PointFeature.h:44
Scalar featureStrength
Feature strength.
Definition: PointFeature.h:165
void setObservation(const Vector2 &position, const DistortionState distortionState)
Sets or changes the 2D observation position of this feature.
Definition: PointFeature.h:220
void setPosition(const Vector3 &position)
Sets or changes the 3D position of this feature.
Definition: PointFeature.h:226
const Vector3 & position() const
Returns the 3D position of this feature e.g.
Definition: PointFeature.h:205
PointFeature()
Creates a new feature object.
Definition: PointFeature.h:171
bool operator==(const PointFeature &feature) const
Returns whether two feature objects are equal.
Definition: PointFeature.h:241
static const Geometry::ImagePoint & feature2imagePoint(const PointFeature &feature)
Converts a point feature to a simple 2D image position.
Definition: PointFeature.h:236
Scalar strength() const
Returns the strength of this feature.
Definition: PointFeature.h:210
Vector2 featureObservation
2D feature observation point.
Definition: PointFeature.h:159
DistortionState
Definition of individual distortion states.
Definition: PointFeature.h:51
@ DS_INVALID
Invalid distortion state.
Definition: PointFeature.h:53
@ DS_UNKNOWN
Unknown distortion state.
Definition: PointFeature.h:55
@ DS_DISTORTED
Distorted position.
Definition: PointFeature.h:57
bool operator!=(const PointFeature &feature) const
Returns whether two feature objects are not equal.
Definition: PointFeature.h:246
const Vector2 & observation() const
Returns the 2D observation position of this feature e.g.
Definition: PointFeature.h:200
DistortionState featureDistortionState
Holds the distortion state of the observation position.
Definition: PointFeature.h:168
DistortionState distortionState() const
Returns the distortion state of the feature point.
Definition: PointFeature.h:215
void setStrength(const Scalar strength)
Sets or changes the strength of this feature.
Definition: PointFeature.h:231
bool operator<(const PointFeature &feature) const
Returns whether the this feature has a higher strength than a second feature object.
Definition: PointFeature.h:251
Vector3 featurePosition
3D feature position.
Definition: PointFeature.h:162
std::vector< PointFeature > PointFeatures
Definition of a vector holding point features.
Definition: PointFeature.h:29
float Scalar
Definition of a scalar type.
Definition: Math.h:128
The namespace covering the entire Ocean framework.
Definition: Accessor.h:15