Ocean
FeatureMap.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_TRACKING_ORB_FEATURE_MAP_H
9 #define META_OCEAN_TRACKING_ORB_FEATURE_MAP_H
10 
11 #include "ocean/tracking/orb/ORB.h"
12 
13 #include "ocean/base/Frame.h"
14 #include "ocean/base/Worker.h"
15 
17 
18 #include "ocean/math/Box2.h"
19 #include "ocean/math/Box3.h"
22 #include "ocean/math/Plane3.h"
23 #include "ocean/math/Vector2.h"
24 
25 namespace Ocean
26 {
27 
28 namespace Tracking
29 {
30 
31 namespace ORB
32 {
33 
34 /**
35  * This class implements a feature map for ORB features.
36  * @ingroup trackingorb
37  */
38 class OCEAN_TRACKING_ORB_EXPORT FeatureMap
39 {
40  public:
41 
42  /**
43  * Creates an empty feature map.
44  */
46 
47  /**
48  * Creates a new feature map by a given image frame.
49  * The frame defines the x-z-plane and the y-axis stays perpendicular on the frame.<br>
50  * The coordinate origin will be defined at the top-left corner of the frame.
51  * @param frame The frame to create a feature map from
52  * @param dimension Width and (optional height) of the frame in reality in meter, if the height is zero it will be defined by the frame's aspect ratio
53  * @param threshold Threshold of feature strength values to be accepted for the feature map
54  * @param frameIsUndistorted True, if the original input frame is undistorted and thus the 2D feature position will be undistorted too
55  * @param maxFeatures Number of maximal features to be stored (sorted by their strength), 0 to use all detected features
56  * @param useHarrisFeatures True, to use Harris corners; False, to use FAST features
57  * @param worker Optional worker object to speed up the process
58  */
59  FeatureMap(const Frame& frame, const Vector2& dimension, const Scalar threshold = Scalar(6.5), const bool frameIsUndistorted = true, const unsigned int maxFeatures = 0u, const bool useHarrisFeatures = false, Worker* worker = nullptr);
60 
61  /**
62  * Projects the bounding box of the feature map into an image plane.
63  * @param pose The camera pose which is the extrinsic camera matrix
64  * @param pinholeCamera The pinhole camera to be used representing the intrinsic camera parameter
65  * @return 2D bounding box of the projected 3D bounding box
66  */
67  Box2 projectToImagePlane(const HomogenousMatrix4& pose, const PinholeCamera& pinholeCamera);
68 
69  /**
70  * Projects the bounding box of the feature map into an image plane.
71  * The resulting 2D bounding box is increased by an extra pixel boundary.
72  * @param pose The camera pose which is the extrinsic camera matrix
73  * @param pinholeCamera The pinhole camera to be used representing the intrinsic camera parameter
74  * @param boundary Extra boundary in pixel
75  * @param left Horizontal start position of the bounding box in pixel
76  * @param top Vertical start position of the bounding box in pixelResulting top position in pixel
77  * @param width Resulting width of the bounding box in pixel
78  * @param height Resulting height of the bounding box in pixel
79  * @param leftClamped Horizontal start position of the bounding box (clamped to the frame dimension)
80  * @param topClamped Horizontal start position of the bounding box (clamped to the frame dimension)
81  * @param widthClamped Horizontal start position of the bounding box (clamped to the frame dimension)
82  * @param heightClamped Horizontal start position of the bounding box (clamped to the frame dimension)
83  * @return True, if succeeded
84  */
85  bool projectToImagePlane(const HomogenousMatrix4& pose, const PinholeCamera& pinholeCamera, const Scalar boundary, int& left, int& top, unsigned int& width, unsigned int& height, unsigned int& leftClamped, unsigned int& topClamped, unsigned int& widthClamped, unsigned int& heightClamped);
86 
87  /**
88  * Projects the bounding box of the feature map into an image plane.
89  * @param iFlippedPose Inverted and flipped extrinsic camera matrix
90  * @param pinholeCamera The pinhole camera to be used representing the intrinsic camera parameter
91  * @return 2D bounding box of the projected 3D bounding box
92  */
93  Box2 projectToImagePlaneIF(const HomogenousMatrix4& iFlippedPose, const PinholeCamera& pinholeCamera);
94 
95  /**
96  * Projects the bounding box of the feature map into an image plane.
97  * The resulting 2D bounding box is increased by an extra pixel boundary and clamped to the frame dimension.
98  * @param iFlippedPose Inverted and flipped extrinsic camera matrix
99  * @param pinholeCamera The pinhole camera to be used representing the intrinsic camera parameter
100  * @param boundary Extra boundary in pixel
101  * @param left Horizontal start position of the bounding box in pixel
102  * @param top Vertical start position of the bounding box in pixelResulting top position in pixel
103  * @param width Resulting width of the bounding box in pixel
104  * @param height Resulting height of the bounding box in pixel
105  * @return True, if succeeded
106  */
107  bool projectToImagePlaneIF(const HomogenousMatrix4& iFlippedPose, const PinholeCamera& pinholeCamera, const Scalar boundary, unsigned int& left, unsigned int& top, unsigned int& width, unsigned int& height);
108 
109  /**
110  * Returns all features determined during creation of the feature map.
111  * @return Map features
112  */
113  inline const CV::Detector::ORBFeatures& features() const;
114 
115  /**
116  * Returns the bounding box of this feature map.
117  * @return Bounding box
118  */
119  inline const Box3& boundingBox() const;
120 
121  /**
122  * Returns the plane of this feature map.
123  * Beware: This plane may be invalid for e.g. 3D feature maps.
124  * @return Plane holding all planar features
125  * @see isPlanar().
126  */
127  inline const Plane3& plane() const;
128 
129  /**
130  * Returns whether the feature map is planar.
131  * @return True, if so
132  */
133  inline bool isPlanar() const;
134 
135  /**
136  * Returns whether the feature map is using Harris corners or FAST features.
137  * @return True, to use Harris corners; False, to use FAST features
138  */
139  inline bool isUsingHarrisFeatures() const;
140 
141  /**
142  * Returns whether this map holds no features.
143  * @return True, if so
144  */
145  inline bool isNull() const;
146 
147  /**
148  * Returns whether this map holds at least one feature.
149  * @return True, if so
150  */
151  explicit inline operator bool() const;
152 
153  /**
154  * Returns features that were projected from the camera plane to the 3D plane of the feature map.
155  * Beware: the size of the features could be zero
156  * @return Projected features.
157  */
158  inline const CV::Detector::ORBFeatures& projectedFeatures() const;
159 
160  /**
161  * Sets additional feature points that were projected from the camera plane to the 3D plane of the feature map.
162  * This will not override the features determined during creation of the map.
163  * @param features Features to set
164  */
165  inline void setProjectedFeatures(CV::Detector::ORBFeatures& features);
166 
167  private:
168 
169  /// All object ORB features corresponding to this map.
171 
172  /// Optional projected ORB features
174 
175  /// Bounding box of the feature map enclosing all object features.
177 
178  /// Plane of the feature map if all feature points are planar.
180 
181  // True, to use Harris corners; False, to use FAST features.
183 };
184 
186 {
187  return projectedFeatures_;
188 }
189 
191 {
193 }
194 
196 {
197  return features_;
198 }
199 
200 inline const Box3& FeatureMap::boundingBox() const
201 {
202  return boundingBox_;
203 }
204 
205 inline bool FeatureMap::isNull() const
206 {
207  return features_.empty();
208 }
209 
210 inline const Plane3& FeatureMap::plane() const
211 {
212  return plane_;
213 }
214 
215 inline bool FeatureMap::isPlanar() const
216 {
217  return plane_.isValid();
218 }
219 
221 {
222  return usingHarrisFeatures_;
223 }
224 
225 inline FeatureMap::operator bool() const
226 {
227  return !features_.empty();
228 }
229 
230 }
231 
232 }
233 
234 }
235 
236 #endif // META_OCEAN_TRACKING_ORB_FEATURE_MAP_H
This class implements Ocean's image class.
Definition: Frame.h:1792
bool isValid() const
Returns whether this plane is valid.
Definition: Plane3.h:538
This class implements a feature map for ORB features.
Definition: FeatureMap.h:39
const Plane3 & plane() const
Returns the plane of this feature map.
Definition: FeatureMap.h:210
bool isPlanar() const
Returns whether the feature map is planar.
Definition: FeatureMap.h:215
Box3 boundingBox_
Bounding box of the feature map enclosing all object features.
Definition: FeatureMap.h:176
CV::Detector::ORBFeatures features_
All object ORB features corresponding to this map.
Definition: FeatureMap.h:170
void setProjectedFeatures(CV::Detector::ORBFeatures &features)
Sets additional feature points that were projected from the camera plane to the 3D plane of the featu...
Definition: FeatureMap.h:190
CV::Detector::ORBFeatures projectedFeatures_
Optional projected ORB features.
Definition: FeatureMap.h:173
bool isUsingHarrisFeatures() const
Returns whether the feature map is using Harris corners or FAST features.
Definition: FeatureMap.h:220
bool projectToImagePlane(const HomogenousMatrix4 &pose, const PinholeCamera &pinholeCamera, const Scalar boundary, int &left, int &top, unsigned int &width, unsigned int &height, unsigned int &leftClamped, unsigned int &topClamped, unsigned int &widthClamped, unsigned int &heightClamped)
Projects the bounding box of the feature map into an image plane.
FeatureMap()
Creates an empty feature map.
const CV::Detector::ORBFeatures & projectedFeatures() const
Returns features that were projected from the camera plane to the 3D plane of the feature map.
Definition: FeatureMap.h:185
const CV::Detector::ORBFeatures & features() const
Returns all features determined during creation of the feature map.
Definition: FeatureMap.h:195
bool usingHarrisFeatures_
Definition: FeatureMap.h:182
Box2 projectToImagePlaneIF(const HomogenousMatrix4 &iFlippedPose, const PinholeCamera &pinholeCamera)
Projects the bounding box of the feature map into an image plane.
Plane3 plane_
Plane of the feature map if all feature points are planar.
Definition: FeatureMap.h:179
bool projectToImagePlaneIF(const HomogenousMatrix4 &iFlippedPose, const PinholeCamera &pinholeCamera, const Scalar boundary, unsigned int &left, unsigned int &top, unsigned int &width, unsigned int &height)
Projects the bounding box of the feature map into an image plane.
FeatureMap(const Frame &frame, const Vector2 &dimension, const Scalar threshold=Scalar(6.5), const bool frameIsUndistorted=true, const unsigned int maxFeatures=0u, const bool useHarrisFeatures=false, Worker *worker=nullptr)
Creates a new feature map by a given image frame.
Box2 projectToImagePlane(const HomogenousMatrix4 &pose, const PinholeCamera &pinholeCamera)
Projects the bounding box of the feature map into an image plane.
bool isNull() const
Returns whether this map holds no features.
Definition: FeatureMap.h:205
const Box3 & boundingBox() const
Returns the bounding box of this feature map.
Definition: FeatureMap.h:200
This class implements a worker able to distribute function calls over different threads.
Definition: Worker.h:33
std::vector< ORBFeature > ORBFeatures
Definition of a vector holding ORB features.
Definition: ORBFeature.h:26
float Scalar
Definition of a scalar type.
Definition: Math.h:128
The namespace covering the entire Ocean framework.
Definition: Accessor.h:15