Ocean
Loading...
Searching...
No Matches
RMVFeatureMap.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_RMV_RMV_FEATURE_MAP_H
9#define META_OCEAN_TRACKING_RMV_RMV_FEATURE_MAP_H
10
13
14#include "ocean/base/Frame.h"
15
17#include "ocean/math/Box3.h"
18
19namespace Ocean
20{
21
22namespace Tracking
23{
24
25namespace RMV
26{
27
28/**
29 * This class implements a feature map.
30 * @ingroup trackingrmv
31 */
32class OCEAN_TRACKING_RMV_EXPORT RMVFeatureMap
33{
34 public:
35
36 /**
37 * Creates an empty feature map.
38 */
40
41 /**
42 * Returns the object positions of the registered map features.
43 * @return Object positions
44 * @see initializationObjectPoints().
45 */
46 inline const Vectors3& objectPoints() const;
47
48 /**
49 * Returns the object points to be used during initialization iterations.
50 * If no explicit initialization object points are defined the standard feature map object points are returned.
51 * @return Initialization object points
52 * @see objectPoints().
53 */
54 inline const Vectors3& initializationObjectPoints() const;
55
56 /**
57 * Returns the indices of the most recently strong object points.
58 * @return Indices of the most recently strong object points
59 */
60 inline const Indices32& recentStrongObjectPointIndices() const;
61
62 /**
63 * Returns the indices of the most recently semi-strong object points.
64 * @return Indices of the most recently semi-strong object points
65 */
66 inline const Indices32& recentSemiStrongObjectPointIndices() const;
67
68 /**
69 * Returns the indices of the most recently used object points.
70 * @return Indices of the most recently used object points
71 */
72 inline const Indices32& recentUsedObjectPointIndices() const;
73
74 /**
75 * Returns the most recently used object points.
76 * Additional this function can return a maximal amount of object points only.
77 * @param maxNumber The maximal number of requested object points, with range [1, infinity)
78 * @return Most recently used object points
79 */
80 inline Vectors3 recentUsedObjectPoints(const size_t maxNumber = size_t(-1)) const;
81
82 /**
83 * Sets or changes the indices of the most recently object points.
84 * @param strongObjectPointIndices Indices of all strong object points, may be a subset of the used object points, with ascending order
85 * @param semiStrongObjectPointIndices Indices of all semi-strong object points, may be a subset of the used object points, the intersection with the strong features must be empty, with ascending order
86 * @param usedObjectPointIndices Indices of all (valid and therefore) use object points, with ascending order
87 */
88 inline void setMostRecentObjectPointIndices(Indices32&& strongObjectPointIndices, Indices32&& semiStrongObjectPointIndices, Indices32&& usedObjectPointIndices);
89
90 /**
91 * Removes / clears the indices of the most recently object points.
92 * The indices of all strong, semi-strong and used object points will be released.<br>
93 */
94 inline void clearMostRecentObjectPointIndices();
95
96 /**
97 * Returns the bounding box of this map.
98 * @return Bounding box
99 * @see initializationBoundingBox().
100 */
101 inline const Box3& boundingBox() const;
102
103 /**
104 * Returns the initialization camera if defined.
105 * @return Initialization camera object
106 */
107 inline const AnyCamera& initializationCamera() const;
108
109 /**
110 * Returns the detector type for the normal feature map.
111 * @return Detector type
112 */
113 inline RMVFeatureDetector::DetectorType detectorType() const;
114
115 /**
116 * Returns the detector type for the initialization features.
117 * @return Initialization detector type
118 */
119 inline RMVFeatureDetector::DetectorType initializationDetectorType() const;
120
121 /**
122 * Returns the bounding box of the initialization feature map.
123 * The bounding box covers all strong features used for initialization.<br>
124 * If no explicit initialization features are specified the bounding box of the standard features is returned.<br>
125 * @return Initialization bounding box
126 * @see boundingBox().
127 */
128 inline const Box3& initializationBoundingBox() const;
129
130 /**
131 * Sets or replaces the features for this feature map by a given set of 3D features points.
132 * @param points The points to be used as new feature map, can be nullptr if number is zero
133 * @param number The number of features to be set, with range [0, infinity)
134 * @param camera The camera profile which will be used during the tracking
135 * @param detectorType The type of the detector which has been used to detect the provided feature points
136 */
137 void setFeatures(const Vector3* points, const size_t number, const SharedAnyCamera& camera, const RMVFeatureDetector::DetectorType detectorType);
138
139 /**
140 * Sets or replaces the features for this feature map by a given tracking pattern.
141 * @param pattern The tracking pattern from which unique and strong feature points will be extracted and stored as feature map, must be valid
142 * @param dimension The dimension of the pattern in the world coordinate system, with range (0, infinity)x[0, infinity)x[0]
143 * @param camera The camera profile which will be used during tracking
144 * @param numberFeatures The maximal number of feature points which will be extracted from the provided pattern, with range [10, infinity)
145 * @param detectorType Detector type the feature points has been detected with
146 * @param worker Optional worker object to distribute the computation
147 * @return True, if succeeded
148 */
149 bool setFeatures(const Frame& pattern, const Vector3& dimension, const SharedAnyCamera& camera, const size_t numberFeatures, const RMVFeatureDetector::DetectorType detectorType, Worker* worker = nullptr);
150
151 /**
152 * Sets or replaces the initialization features for this feature map by a given set of 3D features points.
153 * These features are used for initialization only and thus should be a small subset of strong features.<br>
154 * If no initialization features are specified the normal feature map points are used during initialization.
155 * @param objectPoints The 3D object points to be used as new feature map during initialization iterations, can be nullptr if 'number' is zero
156 * @param number The number of initialization features to be set, with range [0, infinity)
157 * @param initializationCamera Specific initialization camera
158 * @param initializationDetectorType Specific detector type for the initialization
159 */
160 void setInitializationFeatures(const Vector3* objectPoints, const size_t number, const SharedAnyCamera& initializationCamera, const RMVFeatureDetector::DetectorType initializationDetectorType);
161
162 /**
163 * Sets or replaces the initialization features for this feature map by a given set of 3D features points.
164 * These features are used for initialization only and thus should be a small subset of strong features.<br>
165 * If no initialization features are specified the normal feature map points are used during initialization.
166 * @param objectPoints The 3D object points to be used as new feature map during initialization iterations, will be moved
167 * @param initializationCamera Specific initialization camera
168 * @param initializationDetectorType Specific detector type for the initialization
169 */
170 void setInitializationFeatures(Vectors3&& objectPoints, const SharedAnyCamera& initializationCamera, const RMVFeatureDetector::DetectorType initializationDetectorType);
171
172 /**
173 * Sets or replaces the features that will be used during the initialization only for this feature map by a given tracking pattern.
174 * @param pattern The pattern frame the tracker will detect and track, must be valid
175 * @param dimension The dimension of the pattern in the world coordinate system, with range (0, infinity)x[0, infinity)x[0]
176 * @param camera The pinhole camera profile which will be used during the tracking
177 * @param numberInitializationObjectPoints The number of 3D object points that will be used during the initialization, with range [1, infinity)
178 * @param initializationDetectorType The detector type which will be used during the initialization, may be different from the detector type which will be used after a successful initialization
179 * @param worker Optional worker object to distribute the computation
180 * @return True, if succeeded
181 */
182 bool setInitializationFeatures(const Frame& pattern, const Vector3& dimension, const SharedAnyCamera& camera, const size_t numberInitializationObjectPoints, const RMVFeatureDetector::DetectorType& initializationDetectorType, Worker* worker = nullptr);
183
184 /**
185 * Removes all registered map feature points.
186 */
187 void clear();
188
189 /**
190 * Returns whether this feature map holds no feature points.
191 * @return True, if so
192 */
193 inline bool isEmpty() const;
194
195 /**
196 * Returns whether this feature map holds at least one feature point.
197 * @return True, if so
198 */
199 explicit inline operator bool() const;
200
201 /**
202 * Projects a 3D bounding box into the image plane of a given camera.
203 * @param camera The camera profile to be used, must be valid
204 * @param world_T_camera The transformation between camera and world, must be valid
205 * @param objectBoundingBox The bounding box to be projected, must be valid
206 * @return Resulting bounding box in the image plane
207 */
208 static Box2 projectToImage(const AnyCamera& camera, const HomogenousMatrix4& world_T_camera, const Box3& objectBoundingBox);
209
210 /**
211 * Projects a 3D bounding box into the image plane of a given camera.
212 * @param camera The camera profile to be used, must be valid
213 * @param flippedCamera_T_world The transformation between world and flipped camera, must be valid
214 * @param objectBoundingBox The bounding box to be projected, must be valid
215 * @return Resulting bounding box in the image plane
216 */
217 static Box2 projectToImageIF(const AnyCamera& camera, const HomogenousMatrix4& flippedCamera_T_world, const Box3& objectBoundingBox);
218
219 protected:
220
221 /// Object points defining the feature map.
223
224 /// Object points defining the initialization feature map.
226
227 /// Indices of the strongest object points from the most recently tracking iteration.
229
230 /// Indices of the semi-strongest object points from the most recently tracking iteration.
232
233 /// Indices of the used object points from the most recently tracking iteration.
235
236 /// Bounding box covering all feature points.
238
239 /// Bounding box covering all initialization feature points, if existing.
241
242 /// Standard camera.
244
245 /// Camera object explicitly used for camera initialization, if defined.
247
248 /// Detector type used for the normal feature map features.
250
251 /// Detector type explicitly used for initialization features.
253};
254
256{
257 return mapObjectPoints_;
258}
259
264
269
274
280
281inline Vectors3 RMVFeatureMap::recentUsedObjectPoints(const size_t maxNumber) const
282{
283 ocean_assert(maxNumber != 0);
284
285 const size_t number = min(mapRecentUsedObjectPointIndices_.size(), maxNumber);
286
287 Vectors3 result(number);
288
289 for (size_t n = 0; n < number; ++n)
290 {
291 ocean_assert(mapRecentUsedObjectPointIndices_[n] < mapObjectPoints_.size());
293 }
294
295 return result;
296}
297
298inline void RMVFeatureMap::setMostRecentObjectPointIndices(Indices32&& strongObjectPointIndices, Indices32&& semiStrongObjectPointIndices, Indices32&& usedObjectPointIndices)
299{
300
301#ifdef OCEAN_DEBUG
302
303 // check whether the given strong and semi-strong features have no index in common
304 for (const Index32& strongIndex : strongObjectPointIndices)
305 {
306 bool found = false;
307
308 for (const Index32& semiStrongIndex : semiStrongObjectPointIndices)
309 {
310 if (strongIndex == semiStrongIndex)
311 {
312 found = true;
313 break;
314 }
315 }
316
317 ocean_assert(!found);
318 }
319
320 // check whether the order of the index is correct
321
322 for (size_t n = 1; n < strongObjectPointIndices.size(); ++n)
323 {
324 ocean_assert(strongObjectPointIndices[n - 1] < strongObjectPointIndices[n]);
325 }
326
327 for (size_t n = 1; n < semiStrongObjectPointIndices.size(); ++n)
328 {
329 ocean_assert(semiStrongObjectPointIndices[n - 1] < semiStrongObjectPointIndices[n]);
330 }
331
332 for (size_t n = 1; n < usedObjectPointIndices.size(); ++n)
333 {
334 ocean_assert(usedObjectPointIndices[n - 1] < usedObjectPointIndices[n]);
335 }
336
337#endif // OCEAN_DEBUG
338
339 mapRecentStrongObjectPointIndices_ = std::move(strongObjectPointIndices);
340 mapRecentSemiStrongObjectPointIndices_ = std::move(semiStrongObjectPointIndices);
341 mapRecentUsedObjectPointIndices_ = std::move(usedObjectPointIndices);
342}
343
350
351inline const Box3& RMVFeatureMap::boundingBox() const
352{
353 return mapBoundingBox_;
354}
355
362
367
372
377
378inline bool RMVFeatureMap::isEmpty() const
379{
380 return mapObjectPoints_.empty();
381}
382
383inline RMVFeatureMap::operator bool() const
384{
385 return !mapObjectPoints_.empty();
386}
387
388}
389
390}
391
392}
393
394#endif // META_OCEAN_TRACKING_RMV_RMV_FEATURE_MAP_H
This class implements the abstract base class for all AnyCamera objects.
Definition AnyCamera.h:131
bool isValid() const
Returns whether the bounding box is valid.
This class implements Ocean's image class.
Definition Frame.h:1879
DetectorType
Definition of individual feature detectors.
Definition RMVFeatureDetector.h:41
This class implements a feature map.
Definition RMVFeatureMap.h:33
const Box3 & initializationBoundingBox() const
Returns the bounding box of the initialization feature map.
Definition RMVFeatureMap.h:373
void setMostRecentObjectPointIndices(Indices32 &&strongObjectPointIndices, Indices32 &&semiStrongObjectPointIndices, Indices32 &&usedObjectPointIndices)
Sets or changes the indices of the most recently object points.
Definition RMVFeatureMap.h:298
RMVFeatureDetector::DetectorType mapInitializationDetectorType_
Detector type explicitly used for initialization features.
Definition RMVFeatureMap.h:252
Vectors3 mapInitializationObjectPoints_
Object points defining the initialization feature map.
Definition RMVFeatureMap.h:225
Vectors3 recentUsedObjectPoints(const size_t maxNumber=size_t(-1)) const
Returns the most recently used object points.
Definition RMVFeatureMap.h:281
const Box3 & boundingBox() const
Returns the bounding box of this map.
Definition RMVFeatureMap.h:351
RMVFeatureDetector::DetectorType mapDetectorType_
Detector type used for the normal feature map features.
Definition RMVFeatureMap.h:249
void setInitializationFeatures(const Vector3 *objectPoints, const size_t number, const SharedAnyCamera &initializationCamera, const RMVFeatureDetector::DetectorType initializationDetectorType)
Sets or replaces the initialization features for this feature map by a given set of 3D features point...
static Box2 projectToImageIF(const AnyCamera &camera, const HomogenousMatrix4 &flippedCamera_T_world, const Box3 &objectBoundingBox)
Projects a 3D bounding box into the image plane of a given camera.
const Indices32 & recentUsedObjectPointIndices() const
Returns the indices of the most recently used object points.
Definition RMVFeatureMap.h:275
void setFeatures(const Vector3 *points, const size_t number, const SharedAnyCamera &camera, const RMVFeatureDetector::DetectorType detectorType)
Sets or replaces the features for this feature map by a given set of 3D features points.
bool isEmpty() const
Returns whether this feature map holds no feature points.
Definition RMVFeatureMap.h:378
void clearMostRecentObjectPointIndices()
Removes / clears the indices of the most recently object points.
Definition RMVFeatureMap.h:344
Indices32 mapRecentStrongObjectPointIndices_
Indices of the strongest object points from the most recently tracking iteration.
Definition RMVFeatureMap.h:228
const Indices32 & recentStrongObjectPointIndices() const
Returns the indices of the most recently strong object points.
Definition RMVFeatureMap.h:265
const Indices32 & recentSemiStrongObjectPointIndices() const
Returns the indices of the most recently semi-strong object points.
Definition RMVFeatureMap.h:270
SharedAnyCamera mapCamera_
Standard camera.
Definition RMVFeatureMap.h:243
const Vectors3 & initializationObjectPoints() const
Returns the object points to be used during initialization iterations.
Definition RMVFeatureMap.h:260
Vectors3 mapObjectPoints_
Object points defining the feature map.
Definition RMVFeatureMap.h:222
const AnyCamera & initializationCamera() const
Returns the initialization camera if defined.
Definition RMVFeatureMap.h:356
bool setFeatures(const Frame &pattern, const Vector3 &dimension, const SharedAnyCamera &camera, const size_t numberFeatures, const RMVFeatureDetector::DetectorType detectorType, Worker *worker=nullptr)
Sets or replaces the features for this feature map by a given tracking pattern.
Box3 mapInitializationBoundingBox_
Bounding box covering all initialization feature points, if existing.
Definition RMVFeatureMap.h:240
bool setInitializationFeatures(const Frame &pattern, const Vector3 &dimension, const SharedAnyCamera &camera, const size_t numberInitializationObjectPoints, const RMVFeatureDetector::DetectorType &initializationDetectorType, Worker *worker=nullptr)
Sets or replaces the features that will be used during the initialization only for this feature map b...
SharedAnyCamera mapInitializationCamera_
Camera object explicitly used for camera initialization, if defined.
Definition RMVFeatureMap.h:246
RMVFeatureDetector::DetectorType detectorType() const
Returns the detector type for the normal feature map.
Definition RMVFeatureMap.h:368
Indices32 mapRecentUsedObjectPointIndices_
Indices of the used object points from the most recently tracking iteration.
Definition RMVFeatureMap.h:234
Box3 mapBoundingBox_
Bounding box covering all feature points.
Definition RMVFeatureMap.h:237
void clear()
Removes all registered map feature points.
RMVFeatureDetector::DetectorType initializationDetectorType() const
Returns the detector type for the initialization features.
Definition RMVFeatureMap.h:363
void setInitializationFeatures(Vectors3 &&objectPoints, const SharedAnyCamera &initializationCamera, const RMVFeatureDetector::DetectorType initializationDetectorType)
Sets or replaces the initialization features for this feature map by a given set of 3D features point...
static Box2 projectToImage(const AnyCamera &camera, const HomogenousMatrix4 &world_T_camera, const Box3 &objectBoundingBox)
Projects a 3D bounding box into the image plane of a given camera.
Indices32 mapRecentSemiStrongObjectPointIndices_
Indices of the semi-strongest object points from the most recently tracking iteration.
Definition RMVFeatureMap.h:231
RMVFeatureMap()
Creates an empty feature map.
const Vectors3 & objectPoints() const
Returns the object positions of the registered map features.
Definition RMVFeatureMap.h:255
This class implements a worker able to distribute function calls over different threads.
Definition Worker.h:33
std::vector< Index32 > Indices32
Definition of a vector holding 32 bit index values.
Definition Base.h:96
uint32_t Index32
Definition of a 32 bit index value.
Definition Base.h:84
std::shared_ptr< AnyCamera > SharedAnyCamera
Definition of a shared pointer holding an AnyCamera object with Scalar precision.
Definition AnyCamera.h:61
std::vector< Vector3 > Vectors3
Definition of a vector holding Vector3 objects.
Definition Vector3.h:65
The namespace covering the entire Ocean framework.
Definition Accessor.h:15