Ocean
Loading...
Searching...
No Matches
point/Frame2FrameTracker.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_FRAME_2_FRAME_TRACKER_H
9#define META_OCEAN_TRACKING_POINT_FRAME_2_FRAME_TRACKER_H
10
12
13#include "ocean/base/Frame.h"
14#include "ocean/base/Worker.h"
15
17
19
22#include "ocean/math/Vector2.h"
23#include "ocean/math/Vector3.h"
24
26
27namespace Ocean
28{
29
30namespace Tracking
31{
32
33namespace Point
34{
35
36/**
37 * This class implements simple functions allowing to track or to determine the camera motion from one frame to another frame.
38 * @ingroup tracking
39 */
41{
42 public:
43
44 /**
45 * Determines the camera pose for a current camera frame by tracking image points from the previous frame (for which the corresponding 3D object points are known) to the current frame.
46 * @param camera The camera profile defining the projection, must be valid
47 * @param world_T_previousCamera The known camera pose for the previous camera frame, with default camera pointing towards the negative z-axis with y-axis upwards, must be valid
48 * @param previousFrame The previous camera frame, must be valid
49 * @param currentFrame The current camera frame, must be valid with same frame type as the previous frame
50 * @param previousObjectPoints The 3D object point locations corresponding to the image points in the previous frame, define in world, at least 3
51 * @param previousImagePoints The 2D image points defined in the previous camera frame, one for each provided 3D object point
52 * @param maximalOffset The maximal offset of image points between the previous and the current frame in pixel, with range (0, infinity)
53 * @param world_T_currentCamera The resulting camera pose of the current frame
54 * @param validIndices Optional resulting indices of the provided previous image points that could be tracked to the current frame
55 * @param worker Optional worker object to distribute the computation
56 * @tparam tSize The size of the image patches that are used for point tracking, must be odd, with range [1, infinity)
57 */
58 template <unsigned int tSize>
59 static bool determinePose(const AnyCamera& camera, const HomogenousMatrix4& world_T_previousCamera, const Frame& previousFrame, const Frame& currentFrame, const Vectors3& previousObjectPoints, const Vectors2& previousImagePoints, const unsigned int maximalOffset, HomogenousMatrix4& world_T_currentCamera, Indices32* validIndices = nullptr, Worker* worker = nullptr);
60};
61
62template <unsigned int tSize>
63bool Frame2FrameTracker::determinePose(const AnyCamera& camera, const HomogenousMatrix4& world_T_previousCamera, const Frame& previousFrame, const Frame& currentFrame, const Vectors3& previousObjectPoints, const Vectors2& previousImagePoints, const unsigned int maximalOffset, HomogenousMatrix4& world_T_currentCamera, Indices32* validIndices, Worker* worker)
64{
65 ocean_assert(camera.isValid() && world_T_previousCamera.isValid());
66 ocean_assert(previousFrame.isValid() && currentFrame.isValid());
67
68 ocean_assert(previousFrame.frameType() == currentFrame.frameType());
69
70 ocean_assert(previousObjectPoints.size() >= 3);
71 ocean_assert(previousObjectPoints.size() == previousImagePoints.size());
72
73 Vectors2 copyPreviousImagePoints(previousImagePoints);
74
75 Vectors2 currentImagePoints;
76 Indices32 internalValidIndices;
77 if (!CV::Advanced::AdvancedMotionT<>::trackPointsBidirectionalSubPixelMirroredBorder<tSize>(previousFrame, currentFrame, maximalOffset, 2u, copyPreviousImagePoints, currentImagePoints, Scalar(0.9 * 0.9), CV::FramePyramid::DM_FILTER_14641, worker, &internalValidIndices))
78 {
79 return false;
80 }
81
82 if (internalValidIndices.size() < 3)
83 {
84 return false;
85 }
86
87 if (!Geometry::NonLinearOptimizationPose::optimizePose(camera, world_T_previousCamera, ConstArraySubsetAccessor<Vector3, Index32>(previousObjectPoints, internalValidIndices), ConstArraySubsetAccessor<Vector2, Index32>(currentImagePoints, internalValidIndices), world_T_currentCamera))
88 {
89 return false;
90 }
91
92 if (validIndices != nullptr)
93 {
94 *validIndices = std::move(internalValidIndices);
95 }
96
97 return true;
98}
99
100}
101
102}
103
104}
105
106#endif // META_OCEAN_TRACKING_POINT_FRAME_2_FRAME_TRACKER_H
This class implements the abstract base class for all AnyCamera objects.
Definition AnyCamera.h:131
virtual bool isValid() const =0
Returns whether this camera is valid.
This class implements advanced motion techniques (mainly with sub-pixel accuracy or binary masks) all...
Definition AdvancedMotion.h:367
@ DM_FILTER_14641
Down sampling is realized by a 5x5 Gaussian filter.
Definition FramePyramid.h:81
This class implements an indexed-based constant accessor providing access to a subset of elements sto...
Definition Accessor.h:1141
This class implements Ocean's image class.
Definition Frame.h:1969
const FrameType & frameType() const
Returns the frame type of this frame.
Definition Frame.h:4029
bool isValid() const
Returns whether this frame is valid.
Definition Frame.h:4705
static bool optimizePose(const AnyCamera &anyCamera, const HomogenousMatrix4 &world_T_camera, const ConstIndexedAccessor< Vector3 > &objectPoints, const ConstIndexedAccessor< Vector2 > &imagePoints, HomogenousMatrix4 &world_T_optimizedCamera, const unsigned int iterations=20u, const Estimator::EstimatorType estimator=Estimator::ET_SQUARE, Scalar lambda=Scalar(0.001), const Scalar lambdaFactor=10, Scalar *initialError=nullptr, Scalar *finalError=nullptr, Scalars *intermediateRobustErrors=nullptr, const GravityConstraints *gravityConstraints=nullptr)
Minimizes the projection error of a given 6DOF pose holding orientation and translation parameters fo...
Definition NonLinearOptimizationPose.h:235
bool isValid() const
Returns whether this matrix is a valid homogeneous transformation.
Definition HomogenousMatrix4.h:1800
This class implements simple functions allowing to track or to determine the camera motion from one f...
Definition point/Frame2FrameTracker.h:41
static bool determinePose(const AnyCamera &camera, const HomogenousMatrix4 &world_T_previousCamera, const Frame &previousFrame, const Frame &currentFrame, const Vectors3 &previousObjectPoints, const Vectors2 &previousImagePoints, const unsigned int maximalOffset, HomogenousMatrix4 &world_T_currentCamera, Indices32 *validIndices=nullptr, Worker *worker=nullptr)
Determines the camera pose for a current camera frame by tracking image points from the previous fram...
Definition point/Frame2FrameTracker.h:63
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
std::vector< Vector2 > Vectors2
Definition of a vector holding Vector2 objects.
Definition Vector2.h:64
float Scalar
Definition of a scalar type.
Definition Math.h:129
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