Ocean
point/HomographyTracker.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_POINT_HOMOGRAPHY_TRACKER_H
9 #define META_OCEAN_TRACKING_POINT_HOMOGRAPHY_TRACKER_H
10 
12 
13 #include "ocean/base/Frame.h"
15 #include "ocean/base/Worker.h"
16 
17 #include "ocean/cv/FramePyramid.h"
18 
19 #include "ocean/math/AnyCamera.h"
20 #include "ocean/math/Box2.h"
21 #include "ocean/math/Plane3.h"
23 
24 namespace Ocean
25 {
26 
27 namespace Tracking
28 {
29 
30 namespace Point
31 {
32 
33 /**
34  * This class implements a homography-based tracker for planar backgrounds.
35  * The tracker can be started with a region of interest located on a planar background, while the entire surrounding area around the region may also be used for tracking.
36  * @ingroup trackingpoint
37  */
38 class OCEAN_TRACKING_POINT_EXPORT HomographyTracker
39 {
40  protected:
41 
42  /**
43  * Definition of homography qualities.
44  */
46  {
47  /// The homography is invalid.
49  /// The homography has a moderate quality, good enough for visualization, but not good enough to e.g., use the frame as key-frame.
51  /// The homography has a good quality so that the corresponding frame e.g., can be used as key-frame.
52  HQ_GOOD
53  };
54 
55  /**
56  * Definition of a pyramid of 2D image points, mainly a vector with image points located in individual pyramid frames.
57  */
58  typedef std::vector<Vectors2> Vectors2Pyramid;
59 
60  /**
61  * Definition of a pyramid of 3D object points, mainly a vector with object points visible in individual pyramid frames.
62  */
63  typedef std::vector<Vectors3> Vectors3Pyramid;
64 
65  /**
66  * This class composes several parameters necessary for a key-frame.
67  * Key-frames are used for re-initialization of the tracker (whenever the tracker failed during frame-to-frame tracking).
68  */
69  class KeyFrame
70  {
71  public:
72 
73  /**
74  * Creates a new key frame object.
75  */
76  inline KeyFrame();
77 
78  /**
79  * Creates a new key frame object.
80  * @param timestamp The timestamp of the key frame, must be valid
81  * @param initialPointsPyramid The pyramid of points defined in the initial camera frame, corresponding with points defined in the key-frame, one for each key-frame point
82  * @param pointsPyramid The pyramid of points defined in the key-frame (pyramid)
83  * @param pyramid The frame pyramid of the key-frame which can be used for re-localization
84  * @param globalHomography The homography transforming points defined in the initial frame to points defined in the key-frame kHi
85  * @param cameraOrientation The orientation of the camera when creating the key frame, if known.
86  */
87  inline KeyFrame(const Timestamp& timestamp, const Vectors2Pyramid& initialPointsPyramid, const Vectors2Pyramid& pointsPyramid, const CV::FramePyramid& pyramid, const SquareMatrix3& globalHomography, const Quaternion& cameraOrientation);
88 
89  /**
90  * Returns whether this object stores an actual key frame.
91  * @return True, if so
92  */
93  explicit inline operator bool() const;
94 
95  public:
96 
97  /// The timestamp of the key frame.
99 
100  /// The pyramid of points defined in the initial camera frame, corresponding with points defined in the key-frame, one for each key-frame point.
102 
103  /// The pyramid of points defined in the key-frame (pyramid).
105 
106  /// The frame pyramid of the key-frame which can be used for re-localization.
108 
109  /// The homography transforming points defined in the initial frame to points defined in the key-frame (keyFramePoint = globalHomography_ * initialPoint) = kHi.
111 
112  /// The orientation of the camera when creating the key frame, if known.
114  };
115 
116  static constexpr size_t numberKeyFrames_ = 2;
117 
118  public:
119 
120  /**
121  * Creates a new tracker object.
122  */
123  inline HomographyTracker();
124 
125  /**
126  * Sets a new region of interest (or resets an existing region of interest).
127  * The tracker will be set to a new initial state and any resulting homography will be defined in relation to this initial state.
128  * @param camera The camera profile defining the projection, must be valid
129  * @param region The region of interest to be set, defined in the coordinate system of the image frames used for tracking, must be valid
130  * @return True, if succeeded
131  */
132  bool resetRegion(const AnyCamera& camera, const Box2& region);
133 
134  /**
135  * Sets a new region of interest (or resets an existing region of interest).
136  * The tracker will be set to a new initial state and any resulting homography will be defined in relation to this initial state.
137  * @param camera The camera profile defining the projection, must be valid
138  * @param region The region of interest to be set, defined in the coordinate system of the image frames used for tracking, must be valid
139  * @param cameraOrientation The orientation of the camera matching with the given (current) camera frame, defined w.r.t. the world coordinate system (wTc), must be valid
140  * @param planeNormal Normal the planar background at the region of interest, defined w.r.t. the world coordinate system (wN), must be valid
141  * @param pose Optional resulting 6DOF camera pose for the initial camera frame, transforming points defined in the coordinate system of the camera to points defined in the world coordinate system (wTc)
142  * @param plane Optional resulting transformation transforming points defined in the coordinate system of the plane to points defined in the coordinate system of the world coordinate system (wTp)
143  * @return True, if succeeded
144  */
145  bool resetRegion(const AnyCamera& camera, const Box2& region, const Quaternion& cameraOrientation, const Vector3& planeNormal, HomogenousMatrix4* pose = nullptr, HomogenousMatrix4* plane = nullptr);
146 
147  /**
148  * Determines the homography between the current frame and the initial frame.
149  * The initial frame is the frame given after the region of interest has been (re-)set.
150  * @param camera The camera profile defining the projection, must be valid
151  * @param yFrame The current image frame for which the homography will be determined (matching with the camera profile), must have a pixel format FORMAT_Y8, must be valid
152  * @param homography The resulting homography transforming a point defined in the initial frame to a point defined in the current frame (currentPoint = homograph * initialPoint)
153  * @param pose Optional resulting 6DOF camera pose in case the tracker has been reset with a known 3D plane normal, otherwise an invalid pose
154  * @param cameraOrientation The orientation of the camera matching with the given (current) camera frame, defined w.r.t. the world coordinate system (wTc)
155  * @param worker Optional worker object to distribute the computation
156  * @return True, if succeeded
157  */
158  bool determineHomography(const AnyCamera& camera, const Frame& yFrame, SquareMatrix3& homography, HomogenousMatrix4* pose, const Quaternion& cameraOrientation = Quaternion(false), Worker* worker = nullptr);
159 
160  /**
161  * Resets the homography tracker.
162  */
163  inline void reset();
164 
165  protected:
166 
167  /**
168  * Adds new feature points to all pyramid layers (at least to all desired layers e.g., layer 0 and 2) if the layers do not contain enough feature points already.
169  * @param yFramePyramid The frame pyramid of the frame for which the new feature points will be determined, must be valid
170  * @param pointsPyramid The pyramid of already existing feature points for the given frame (individual points for individual pyramid layers)
171  * @param initialPointsPyramid The pyramid of feature points defined in the initial camera frame corresponding with the points in 'pointsPyramid'
172  * @param homography The homography transforming points defined in the initial camera frame to points defined in the given camera frame (pyramid), must be valid, (currentPoint = homography * initialPoint)
173  * @param region The region of interest defined in the initial camera frame, this region will be used prioritize feature points in this area, can be invalid if no region of interest is known
174  * @param minimalFeatures The minimal number of feature points each pyramid layer should contain, with range [1, infinity)
175  * @param maximalFeatures The maximal number of feature points each pyramid layer should contain, with range [minimalFeatures, infinity)
176  * @param worker Optional worker object to distribute the computation
177  * @return True, if succeeded
178  * @see addNewFeaturePointsToPyramidLayer().
179  */
180  static bool addNewFeaturePointsToPyramid(const CV::FramePyramid& yFramePyramid, Vectors2Pyramid& pointsPyramid, Vectors2Pyramid& initialPointsPyramid, const Box2& region, const SquareMatrix3& homography, const unsigned int minimalFeatures = 30u, const unsigned int maximalFeatures = 60u, Worker* worker = nullptr);
181 
182  /**
183  * Adds new feature points to one specific pyramid layer if the layer does not contain enough feature points already.
184  * This function is supposed to be called out of 'addNewFeaturePointsToPyramid()'
185  * @param yFramePyramid The frame pyramid of the frame for which the new feature points will be determined, must be valid
186  * @param pointsPyramid The pyramid of already existing feature points (individual points for individual pyramid layers)
187  * @param layerSubRegionTriangles The triangles defined a sub-region within the specified layer in which more feature points will be determined compared to the surrounding area, no triangle to avoid the usage of a hot spot
188  * @param layer The pyramid layer for which the new feature points will be added, with range [0, yFramePyramid.size() - 1]
189  * @param featureThreshold The strength threshold each new feature point must exceed to count as new feature candidate, with range [0, 255]
190  * @param minimalFeatures The minimal number of feature points each pyramid layer should contain, with range [1, infinity)
191  * @param maximalFeatures The maximal number of feature points (the ideal number of feature points) the pyramid layer should contain, in case the layer contains more points already, no additional point is added, with range [minimalFeatures, infinity)
192  * @param worker Optional worker object to distribute the computation
193  * @return True, if succeeded
194  * @see addNewFeaturePointsToPyramid().
195  */
196  static bool addNewFeaturePointsToPyramidLayer(const CV::FramePyramid& yFramePyramid, Vectors2Pyramid& pointsPyramid, const Triangles2& layerSubRegionTriangles, const unsigned int layer, const unsigned int featureThreshold = 25u, const unsigned int minimalFeatures = 30u, const unsigned int maximalFeatures = 60u, Worker* worker = nullptr);
197 
198  /**
199  * @param yPreviousFramePyramid The pyramid image of the previous frame with pixel format FORMAT_Y8 (1 channel, uint8_t), must be valid
200  * @param yCurrentFramePyramid The pyramid image of the current frame with same pixel format as 'yPreviousFramePyramid', must be valid
201  * @param previousPointsPyramid The image points located in the pyramid image of the previous frame, which will be tracked to the current frame, (with different points for different pyramid layers)
202  * @param currentPointsPyramid The resulting image points located in the pyramid image of the current frame, one point for each point in the corresponding previous image layer
203  * @param startLayer The layer within the pyramid image of the previous frame from which the image points will be tracked, with range [0, yPreviousFramePyramid.layers() - 1]
204  * @param maximalOffsetPercent The maximal pixel offset between corresponding image points defined in percentage in relation to the max(layerWidth, layerHeight), with range [0, 1]
205  * @param validTrackedPointIndices The resulting indices of all previous image points which could be tracked reliably
206  * @param roughHomography Optional homography providing a rough guess for the location of the points in the current frame, defined for the finest pyramid layer (finestCurrentPoint = roughHomography * finestPreviousPoint), a null matrix otherwise
207  * @param coarsestLayerRadius The search radius on the coarsest pyramid layer used for tracking, with range [1, infinity)
208  * @param subPixelIterations The number of sub-pixel iterations that will be applied, each iteration doubles the sub-pixel accuracy, with range [1, infinity)
209  * @param worker Optional worker object to distribute the computation
210  * @return True, if succeeded
211  */
212  static bool trackPoints(const CV::FramePyramid& yPreviousFramePyramid, const CV::FramePyramid& yCurrentFramePyramid, Vectors2Pyramid& previousPointsPyramid, Vectors2Pyramid& currentPointsPyramid, const unsigned int startLayer, const float maximalOffsetPercent, Indices32& validTrackedPointIndices, const SquareMatrix3& roughHomography = SquareMatrix3(false), const unsigned int coarsestLayerRadius = 2u, const unsigned int subPixelIterations = 2u, Worker* worker = nullptr);
213 
214  /**
215  * Determines the homography between two consecutive camera frames based on known feature points located in the previous frame (pyramid).
216  * @param camera The camera profile defining the projection, must be valid
217  * @param plane The 3D plane on which the image points (the corresponding 3D object points) are located, must be valid
218  * @param yPreviousFramePyramid The frame pyramid of the previous camera frame, must have a pixel format FORMAT_Y8, must be valid
219  * @param yCurrentFramePyramid The frame pyramid of the current camera frame, must have a pixel format FORMAT_Y8, must be valid
220  * @param previousPointsPyramid The pyramid of known points located in the previous camera frame, these points will be used for homography estimation, points which could not be used for tracking will be removed during homography estimation, must be valid
221  * @param currentPointsPyramid The resulting pyramid of points located in the current camera frame, one point of each point in the pyramid of points for the previous camera frame 'previousPointsPyramid'
222  * @param initialPointsPyramid The pyramid of known points located in the initial camera frame, one point of each point in the pyramid of points for the previous camera frame 'previousPointsPyramid'
223  * @param previousHomography The known homography transforming points defined in the initial camera frame to points defined in the previous camera frame (defined for the finest pyramid layer), must be valid, (previousPoint = previousHomography * initialPoint)
224  * @param region The region of interest within the camera frame, must be valid
225  * @param homography The resulting homography transforming points defined in the initial camera frame to points defined in the current camera frame (defined for the finest pyramid layer), (currentPoint = previousHomography * initialPoint)
226  * @param pose Optional resulting 6DOF camera pose in case the tracker has been reset with a known 3D plane normal, otherwise an invalid pose
227  * @param predictedLocalHomography Optional known prediction of the homography transformation points defined in the previous camera frame to points defined in the current camera frame, a null matrix otherwise, (currentPoint = predictedLocalHomography * previousPoint)
228  * @param initialCameraOrientation The orientation of the camera frame for the initial frame, (wRi), if known
229  * @param currentCameraOrientation The orientation of the camera frame for the current frame, (wRc), if known
230  * @param randomGenerator Random generator to be used
231  * @param explicitMaximalOffsetPercent An explicit threshold defining the maximal offset between two corresponding feature points, defined in relation to the maximal frame size, with range [0, 1], -1 to use internal thresholds
232  * @param worker Optional worker object to distribute the computation
233  * @return True, if succeeded
234  */
235  static HomographyQuality determineHomographyWithPyramid(const AnyCamera& camera, const Plane3& plane, const CV::FramePyramid& yPreviousFramePyramid, const CV::FramePyramid& yCurrentFramePyramid, Vectors2Pyramid& previousPointsPyramid, Vectors2Pyramid& currentPointsPyramid, Vectors2Pyramid& initialPointsPyramid, const SquareMatrix3& previousHomography, const Box2& region, SquareMatrix3& homography, HomogenousMatrix4* pose, const SquareMatrix3& predictedLocalHomography, const Quaternion& initialCameraOrientation, const Quaternion& currentCameraOrientation, RandomGenerator& randomGenerator, const float explicitMaximalOffsetPercent = -1.0f, Worker* worker = nullptr);
236 
237  /**
238  * Returns whether the region of interest is visible based on a simple angle threshold.
239  * The function determines the angle between viewing direction (the z-axis) for the current frame and the initial frame.<br>
240  * In case, the viewing angle exceeds a specified threshold, the region is rated to be invisible.<br>
241  * If one or both provided camera orientation are unknown, the region is rated to be visible.
242  * @param wRi The rotation of the camera matching with the initial camera frame, can be invalid if unknown
243  * @param wRc The rotation of the camera matching with the current camera frame, can be invalid if unknown
244  * @param maximalAngle The maximal angle between both viewing directions, in radian, with range [0, PI_2]
245  */
246  static bool isRegionVisible(const Quaternion& wRi, const Quaternion& wRc, const Scalar maximalAngle = Numeric::deg2rad(50));
247 
248  /**
249  * Returns whether the region of interest is visible based on the known homography for the current frame.
250  * @param camera The camera profile defining the projection, must be valid
251  * @param globalHomography The homography transforming initial image points to current image points: currentImagePoint = globalHomography_ * initialImagePoint, (globalHomography_ = cHi)
252  * @param initialRegion The initial region of interest, must be valid
253  * @return True, if so
254  */
255  static bool isRegionVisible(const AnyCamera& camera, const SquareMatrix3& globalHomography, const Box2& initialRegion);
256 
257  /**
258  * Returns whether a given homography is plausible in the context of a previous homography.
259  * Based on a region of interest, the homography is rated based on the angular difference within the transformed region of interest.<br>
260  * In case, the angle between two neighboring edges of the ROI exceeds a given threshold, the homography is rated is invalid.
261  * @param pHi The homography transforming points defined in the initial camera frame to points defined in the previous camera frame (previousPoint = pHi * initialPoint), must be valid
262  * @param cHi The homography transforming points defined in the initial camera frame to points defined in the current camera frame (currentPoint = cHi * initialPoint), must be valid
263  * @param initialRegion The region of interest defined in the initial camera frame, must be valid
264  * @param maximalAngleChange The maximal allowed change of inner angles of the ROI so that the homography counts as plausible, in radian, with range [0, PI_4]
265  * @return True, if so
266  */
267  static bool isHomographyPlausible(const SquareMatrix3& pHi, const SquareMatrix3& cHi, const Box2& initialRegion, const Scalar maximalAngleChange = Numeric::deg2rad(5));
268 
269  /**
270  * Returns whether a given 6DOF camera pose if plausible based on e.g., an IMU-based camera orientation.
271  * @param currentPose The current 6DOF camera pose to be checked, must be valid
272  * @param initialCameraOrientation The orientation of the initial camera frame, (wTi), if known
273  * @param currentCameraOrientation The orientation of the current camera frame, (wTc), if known
274  * @param maximalAngle The maximal angle between the orientation of the given 6DOF camera pose and the IMU-based camera orientation so that the pose counts as plausible, in radian, with range [0, PI_2]
275  * @return True, if so
276  */
277  static bool isPosePlausible(const HomogenousMatrix4& currentPose, const Quaternion& initialCameraOrientation, const Quaternion& currentCameraOrientation, const Scalar maximalAngle = Numeric::deg2rad(3));
278 
279  protected:
280 
281  /// The frame pyramid of the previous frame.
283 
284  /// The frame pyramid of the current frame.
286 
287  /// The random generator object.
289 
290  /// The image points located in the coordinate system of the initial frame (the frame in which the tracking region has been defined).
292 
293  /// The image points located in 'previousFramePyramid_'.
295 
296  /// The orientation of the initial camera frame, (wRi), if known.
298 
299  /// The orientation of the camera matching with the previous camera frame, defined w.r.t. the world coordinate system (wTp).
301 
302  /// The homography transforming initial image points to current image points: currentImagePoint = globalHomography_ * initialImagePoint, (globalHomography_ = cHi).
304 
305  /// The orientation of the camera frame for the last valid homography 'globalHomography_' (wTl), if known.
307 
308  /// The tracking region (the region of interest) located on the plane, defined in the coordinate system of the initial frame.
310 
311  /// The 3D plane on which all feature points will be located, if known.
313 
314  /// The two key frames which will be used during re-initialization.
315  KeyFrame keyFrames_[numberKeyFrames_];
316 
317  /// True, if the tracker needs to be re-initialized.
318  bool needsReInitialization_ = false;
319 };
320 
322  timestamp_(false),
323  globalHomography_(false),
324  cameraOrientation_(false)
325 {
326  // nothing to do here
327 }
328 
329 inline HomographyTracker::KeyFrame::KeyFrame(const Timestamp& timestamp, const Vectors2Pyramid& initialPointsPyramid, const Vectors2Pyramid& pointsPyramid, const CV::FramePyramid& pyramid, const SquareMatrix3& globalHomography, const Quaternion& cameraOrientation) :
330  timestamp_(timestamp),
331  initialPointsPyramid_(initialPointsPyramid),
332  pointsPyramid_(pointsPyramid),
333  pyramid_(pyramid, true /*copyData*/),
334  globalHomography_(globalHomography),
335  cameraOrientation_(cameraOrientation)
336 {
337  // nothing to do here
338 }
339 
340 inline HomographyTracker::KeyFrame::operator bool() const
341 {
342  ocean_assert(timestamp_.isValid() == pyramid_.isValid());
343 
344  return timestamp_.isValid();
345 }
346 
350  globalHomography_(false),
353 {
354  // nothing to do here
355 }
356 
358 {
361 
362  initialPointsPyramid_.clear();
363  previousPointsPyramid_.clear();
364 
366 
368 
371 
372  region_ = Box2();
373  plane_ = Plane3();
374 
375  for (size_t n = 0; n < numberKeyFrames_; ++n)
376  {
377  keyFrames_[n] = KeyFrame();
378  }
379 
380  needsReInitialization_ = false;
381 }
382 
383 }
384 
385 }
386 
387 }
388 
389 #endif // META_OCEAN_TRACKING_POINT_HOMOGRAPHY_TRACKER_H
This class implements the abstract base class for all AnyCamera objects.
Definition: AnyCamera.h:130
This class implements a frame pyramid.
Definition: FramePyramid.h:37
void clear()
Releases the internal frame layers.
Definition: FramePyramid.h:845
This class implements Ocean's image class.
Definition: Frame.h:1760
static constexpr T deg2rad(const T deg)
Converts deg to rad.
Definition: Numeric.h:3232
This class implements a generator for random numbers.
Definition: RandomGenerator.h:42
void toNull()
Sets the matrix to a zero matrix.
Definition: SquareMatrix3.h:1311
This class implements a timestamp.
Definition: Timestamp.h:36
This class composes several parameters necessary for a key-frame.
Definition: point/HomographyTracker.h:70
Vectors2Pyramid initialPointsPyramid_
The pyramid of points defined in the initial camera frame, corresponding with points defined in the k...
Definition: point/HomographyTracker.h:101
Vectors2Pyramid pointsPyramid_
The pyramid of points defined in the key-frame (pyramid).
Definition: point/HomographyTracker.h:104
KeyFrame()
Creates a new key frame object.
Definition: point/HomographyTracker.h:321
Quaternion cameraOrientation_
The orientation of the camera when creating the key frame, if known.
Definition: point/HomographyTracker.h:113
Timestamp timestamp_
The timestamp of the key frame.
Definition: point/HomographyTracker.h:98
SquareMatrix3 globalHomography_
The homography transforming points defined in the initial frame to points defined in the key-frame (k...
Definition: point/HomographyTracker.h:110
CV::FramePyramid pyramid_
The frame pyramid of the key-frame which can be used for re-localization.
Definition: point/HomographyTracker.h:107
This class implements a homography-based tracker for planar backgrounds.
Definition: point/HomographyTracker.h:39
HomographyTracker()
Creates a new tracker object.
Definition: point/HomographyTracker.h:347
static bool isRegionVisible(const AnyCamera &camera, const SquareMatrix3 &globalHomography, const Box2 &initialRegion)
Returns whether the region of interest is visible based on the known homography for the current frame...
bool determineHomography(const AnyCamera &camera, const Frame &yFrame, SquareMatrix3 &homography, HomogenousMatrix4 *pose, const Quaternion &cameraOrientation=Quaternion(false), Worker *worker=nullptr)
Determines the homography between the current frame and the initial frame.
bool resetRegion(const AnyCamera &camera, const Box2 &region, const Quaternion &cameraOrientation, const Vector3 &planeNormal, HomogenousMatrix4 *pose=nullptr, HomogenousMatrix4 *plane=nullptr)
Sets a new region of interest (or resets an existing region of interest).
static HomographyQuality determineHomographyWithPyramid(const AnyCamera &camera, const Plane3 &plane, const CV::FramePyramid &yPreviousFramePyramid, const CV::FramePyramid &yCurrentFramePyramid, Vectors2Pyramid &previousPointsPyramid, Vectors2Pyramid &currentPointsPyramid, Vectors2Pyramid &initialPointsPyramid, const SquareMatrix3 &previousHomography, const Box2 &region, SquareMatrix3 &homography, HomogenousMatrix4 *pose, const SquareMatrix3 &predictedLocalHomography, const Quaternion &initialCameraOrientation, const Quaternion &currentCameraOrientation, RandomGenerator &randomGenerator, const float explicitMaximalOffsetPercent=-1.0f, Worker *worker=nullptr)
Determines the homography between two consecutive camera frames based on known feature points located...
bool resetRegion(const AnyCamera &camera, const Box2 &region)
Sets a new region of interest (or resets an existing region of interest).
static bool isRegionVisible(const Quaternion &wRi, const Quaternion &wRc, const Scalar maximalAngle=Numeric::deg2rad(50))
Returns whether the region of interest is visible based on a simple angle threshold.
bool needsReInitialization_
True, if the tracker needs to be re-initialized.
Definition: point/HomographyTracker.h:318
static constexpr size_t numberKeyFrames_
Definition: point/HomographyTracker.h:116
Box2 region_
The tracking region (the region of interest) located on the plane, defined in the coordinate system o...
Definition: point/HomographyTracker.h:309
static bool trackPoints(const CV::FramePyramid &yPreviousFramePyramid, const CV::FramePyramid &yCurrentFramePyramid, Vectors2Pyramid &previousPointsPyramid, Vectors2Pyramid &currentPointsPyramid, const unsigned int startLayer, const float maximalOffsetPercent, Indices32 &validTrackedPointIndices, const SquareMatrix3 &roughHomography=SquareMatrix3(false), const unsigned int coarsestLayerRadius=2u, const unsigned int subPixelIterations=2u, Worker *worker=nullptr)
CV::FramePyramid previousFramePyramid_
The frame pyramid of the previous frame.
Definition: point/HomographyTracker.h:282
SquareMatrix3 globalHomography_
The homography transforming initial image points to current image points: currentImagePoint = globalH...
Definition: point/HomographyTracker.h:303
RandomGenerator randomGenerator_
The random generator object.
Definition: point/HomographyTracker.h:288
void reset()
Resets the homography tracker.
Definition: point/HomographyTracker.h:357
static bool addNewFeaturePointsToPyramidLayer(const CV::FramePyramid &yFramePyramid, Vectors2Pyramid &pointsPyramid, const Triangles2 &layerSubRegionTriangles, const unsigned int layer, const unsigned int featureThreshold=25u, const unsigned int minimalFeatures=30u, const unsigned int maximalFeatures=60u, Worker *worker=nullptr)
Adds new feature points to one specific pyramid layer if the layer does not contain enough feature po...
std::vector< Vectors3 > Vectors3Pyramid
Definition of a pyramid of 3D object points, mainly a vector with object points visible in individual...
Definition: point/HomographyTracker.h:63
KeyFrame keyFrames_[numberKeyFrames_]
The two key frames which will be used during re-initialization.
Definition: point/HomographyTracker.h:315
Vectors2Pyramid initialPointsPyramid_
The image points located in the coordinate system of the initial frame (the frame in which the tracki...
Definition: point/HomographyTracker.h:291
static bool isPosePlausible(const HomogenousMatrix4 &currentPose, const Quaternion &initialCameraOrientation, const Quaternion &currentCameraOrientation, const Scalar maximalAngle=Numeric::deg2rad(3))
Returns whether a given 6DOF camera pose if plausible based on e.g., an IMU-based camera orientation.
Plane3 plane_
The 3D plane on which all feature points will be located, if known.
Definition: point/HomographyTracker.h:312
Quaternion previousCameraOrientation_
The orientation of the camera matching with the previous camera frame, defined w.r....
Definition: point/HomographyTracker.h:300
static bool isHomographyPlausible(const SquareMatrix3 &pHi, const SquareMatrix3 &cHi, const Box2 &initialRegion, const Scalar maximalAngleChange=Numeric::deg2rad(5))
Returns whether a given homography is plausible in the context of a previous homography.
HomographyQuality
Definition of homography qualities.
Definition: point/HomographyTracker.h:46
@ HQ_FAILED
The homography is invalid.
Definition: point/HomographyTracker.h:48
@ HQ_MODERATE
The homography has a moderate quality, good enough for visualization, but not good enough to e....
Definition: point/HomographyTracker.h:50
Vectors2Pyramid previousPointsPyramid_
The image points located in 'previousFramePyramid_'.
Definition: point/HomographyTracker.h:294
std::vector< Vectors2 > Vectors2Pyramid
Definition of a pyramid of 2D image points, mainly a vector with image points located in individual p...
Definition: point/HomographyTracker.h:58
Quaternion globalCameraOrientation_
The orientation of the camera frame for the last valid homography 'globalHomography_' (wTl),...
Definition: point/HomographyTracker.h:306
Quaternion initialCameraOrientation_
The orientation of the initial camera frame, (wRi), if known.
Definition: point/HomographyTracker.h:297
static bool addNewFeaturePointsToPyramid(const CV::FramePyramid &yFramePyramid, Vectors2Pyramid &pointsPyramid, Vectors2Pyramid &initialPointsPyramid, const Box2 &region, const SquareMatrix3 &homography, const unsigned int minimalFeatures=30u, const unsigned int maximalFeatures=60u, Worker *worker=nullptr)
Adds new feature points to all pyramid layers (at least to all desired layers e.g....
CV::FramePyramid currentFramePyramid_
The frame pyramid of the current frame.
Definition: point/HomographyTracker.h:285
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
QuaternionT< Scalar > Quaternion
Definition of the Quaternion object, depending on the OCEAN_MATH_USE_SINGLE_PRECISION either with sin...
Definition: Quaternion.h:33
SquareMatrixT3< Scalar > SquareMatrix3
Definition of the SquareMatrix3 object, depending on the OCEAN_MATH_USE_SINGLE_PRECISION either with ...
Definition: SquareMatrix3.h:35
float Scalar
Definition of a scalar type.
Definition: Math.h:128
std::vector< Triangle2 > Triangles2
Definition of a vector holding 2D triangles.
Definition: Triangle2.h:57
PlaneT3< Scalar > Plane3
Definition of the Plane3 object, depending on the OCEAN_MATH_USE_SINGLE_PRECISION either with single ...
Definition: Plane3.h:24
BoxT2< Scalar > Box2
Definition of the Box2 object, depending on the OCEAN_MATH_USE_SINGLE_PRECISION either with single or...
Definition: Box2.h:22
The namespace covering the entire Ocean framework.
Definition: Accessor.h:15