Ocean
Loading...
Searching...
No Matches
CameraPose.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_SLAM_CAMERA_POSE_H
9#define META_OCEAN_TRACKING_SLAM_CAMERA_POSE_H
10
12
13#include "ocean/math/Camera.h"
15
16namespace Ocean
17{
18
19namespace Tracking
20{
21
22namespace SLAM
23{
24
25// Forward declaration.
26class LocalizedObjectPoint;
27
28// Forward declaration.
29class CameraPose;
30
31/**
32 * Definition of a shared pointer holding a CameraPose object.
33 * @see CameraPose
34 * @ingroup trackingslam
35 */
36using SharedCameraPose = std::shared_ptr<CameraPose>;
37
38/**
39 * This class holds the camera pose of a camera in relation to the world.
40 * The pose includes both the standard camera-to-world transformation and the flipped camera-to-world transformation.<br>
41 * Additionally, each pose stores a quality indicator reflecting the reliability of the pose estimation, and an estimated motion type indicating whether the camera is stationary or moving.<br>
42 * Each pose is tagged with a map version to ensure consistency with the SLAM feature map it was computed against.
43 * @ingroup trackingslam
44 */
45class OCEAN_TRACKING_SLAM_EXPORT CameraPose
46{
47 friend class CameraPoses;
48
49 public:
50
51 /**
52 * Definition of the quality of a camera pose.
53 */
54 enum PoseQuality : uint32_t
55 {
56 /// The pose is invalid.
57 PQ_INVALID = 0u,
58 /// The pose has a low quality as it is based on few feature correspondences.
60 /// The pose has a medium quality as it is based on a medium number of feature correspondences.
62 /// The pose is accurate as it is based on a full bundle adjustment.
63 PQ_HIGH
64 };
65
66 /**
67 * Definition of different types of estimated motion.
68 */
69 enum EstimatedMotion : uint32_t
70 {
71 /// The motion is unknown.
72 EM_UNKNOWN = 0u,
73 /// The camera is stationary (not moving).
75 /// The camera is undergoing translational motion.
76 EM_TRANSLATIONAL
77 };
78
79 public:
80
81 /**
82 * Creates a new invalid camera pose.
83 */
84 CameraPose() = default;
85
86 /**
87 * Creates a new camera pose.
88 * @param world_T_camera The transformation between camera and world, with default camera pointing towards the negative z-space and y-axis upwards, must be valid
89 * @param flippedCamera_T_world The transformation between world and flipped camera, with default flipped camera pointing towards the positive z-space and y-axis downwards, must be valid
90 * @param poseQuality The quality of the pose, must be valid
91 * @param estimatedMotion The estimated motion type of the camera, EM_UNKNOWN if unknown
92 */
93 inline CameraPose(const HomogenousMatrix4& world_T_camera, const HomogenousMatrix4& flippedCamera_T_world, const PoseQuality poseQuality, const EstimatedMotion estimatedMotion = EM_UNKNOWN);
94
95 /**
96 * Creates a new camera pose.
97 * This constructor calculates the transformation between world and flipped camera.
98 * @param world_T_camera The transformation between camera and world, with default camera pointing towards the negative z-space and y-axis upwards, must be valid
99 * @param poseQuality The quality of the pose, must be valid
100 * @param estimatedMotion The estimated motion type of the camera, EM_UNKNOWN if unknown
101 */
102 inline CameraPose(const HomogenousMatrix4& world_T_camera, const PoseQuality poseQuality, const EstimatedMotion estimatedMotion = EM_UNKNOWN);
103
104 /**
105 * Returns the transformation between camera and world.
106 * The default camera points towards the negative z-space with y-axis upwards.
107 * @return The camera-to-world transformation
108 */
109 inline const HomogenousMatrix4& world_T_camera() const;
110
111 /**
112 * Returns the transformation between world and flipped camera.
113 * The default flipped camera points towards the positive z-space with y-axis downwards.
114 * @return The world-to-flipped-camera transformation
115 */
116 inline const HomogenousMatrix4& flippedCamera_T_world() const;
117
118 /**
119 * Returns the quality of this pose.
120 * @return The pose quality
121 */
122 inline PoseQuality poseQuality() const;
123
124 /**
125 * Returns the estimated motion type of the camera.
126 * @return The estimated motion type
127 */
128 inline EstimatedMotion estimatedMotion() const;
129
130 /**
131 * Returns the version of the map used when this pose was computed.
132 * The map version is used to ensure consistency between poses and the feature map they were computed against.
133 * @return The map version, with range [0, infinity), -1 if not yet set
134 */
135 inline Index32 mapVersion() const;
136
137 /**
138 * Returns whether this camera pose is valid.
139 * @return True, if so
140 */
141 inline bool isValid() const;
142
143 /**
144 * Returns whether two camera poses are identical.
145 * @param right The right camera pose to compare
146 * @return True, if so
147 */
148 bool operator==(const CameraPose& right) const = default;
149
150 /**
151 * Translates the given pose quality to a string.
152 * @param poseQuality The pose quality to translate
153 * @return The translated string, 'Invalid' if invalid or unknown
154 */
155 static std::string translatePoseQuality(const PoseQuality poseQuality);
156
157 /**
158 * Determines the estimated motion type from optical flow data.
159 * @param imagePointSqrDistances The squared distances of optical flow vectors, must be valid
160 * @param size The number of elements in imagePointSqrDistances, with range [1, infinity)
161 * @param width The width of the image in pixels, with range [1, infinity)
162 * @param height The height of the image in pixels, with range [1, infinity)
163 * @return The estimated motion type based on the optical flow analysis
164 */
165 static EstimatedMotion motionFromOpticalFlow(const Scalar* imagePointSqrDistances, const size_t size, const unsigned int width, const unsigned int height);
166
167 protected:
168
169 /**
170 * Sets the version of the map used when this pose was computed.
171 * @param mapVersion The map version to set, with range [0, infinity)
172 */
173 inline void setMapVersion(const Index32 mapVersion);
174
175 protected:
176
177 /// The transformation between camera and world, with default camera pointing towards the negative z-space and y-axis upwards.
178 HomogenousMatrix4 world_T_camera_ = HomogenousMatrix4(false);
179
180 /// The transformation between world and flipped camera, with default flipped camera pointing towards the positive z-space and y-axis downwards.
181 HomogenousMatrix4 flippedCamera_T_world_ = HomogenousMatrix4(false);
182
183 /// The quality of the pose.
184 PoseQuality poseQuality_ = PQ_INVALID;
185
186 /// The estimated motion type of the camera.
187 EstimatedMotion estimatedMotion_ = EM_UNKNOWN;
188
189 /// The version of the map used when this pose was computed.
190 Index32 mapVersion_ = Index32(-1);
191};
192
193inline CameraPose::CameraPose(const HomogenousMatrix4& world_T_camera, const HomogenousMatrix4& flippedCamera_T_world, const PoseQuality poseQuality, const EstimatedMotion estimatedMotion) :
194 world_T_camera_(world_T_camera),
195 flippedCamera_T_world_(flippedCamera_T_world),
196 poseQuality_(poseQuality),
197 estimatedMotion_(estimatedMotion)
198{
199 ocean_assert(isValid());
200}
201
202inline CameraPose::CameraPose(const HomogenousMatrix4& world_T_camera, const PoseQuality poseQuality, const EstimatedMotion estimatedMotion) :
203 CameraPose(world_T_camera, Camera::standard2InvertedFlipped(world_T_camera), poseQuality, estimatedMotion)
204{
205 // nothing to do here
206}
207
209{
210 return world_T_camera_;
211}
212
217
222
227
229{
230 return mapVersion_;
231}
232
233inline void CameraPose::setMapVersion(const Index32 mapVersion)
234{
236}
237
238inline bool CameraPose::isValid() const
239{
241
243 {
244 return false;
245 }
246
248
249 return true;
250}
251
252}
253
254}
255
256}
257
258#endif // META_OCEAN_TRACKING_SLAM_CAMERA_POSE_H
static HomogenousMatrixT4< U > invertedFlipped2Standard(const HomogenousMatrixT4< U > &flippedCamera_T_world)
Transforms an inverted and flipped camera pose into a standard camera pose.
Definition Camera.h:801
bool isValid() const
Returns whether this matrix is a valid homogeneous transformation.
Definition HomogenousMatrix4.h:1806
bool isEqual(const HomogenousMatrixT4< T > &matrix, const T epsilon=NumericT< T >::eps()) const
Returns whether two matrices are almost identical up to a specified epsilon.
Definition HomogenousMatrix4.h:1821
static constexpr T weakEps()
Returns a weak epsilon.
This class holds the camera pose of a camera in relation to the world.
Definition CameraPose.h:46
Index32 mapVersion_
The version of the map used when this pose was computed.
Definition CameraPose.h:190
HomogenousMatrix4 flippedCamera_T_world_
The transformation between world and flipped camera, with default flipped camera pointing towards the...
Definition CameraPose.h:181
const HomogenousMatrix4 & flippedCamera_T_world() const
Returns the transformation between world and flipped camera.
Definition CameraPose.h:213
HomogenousMatrix4 world_T_camera_
The transformation between camera and world, with default camera pointing towards the negative z-spac...
Definition CameraPose.h:178
Index32 mapVersion() const
Returns the version of the map used when this pose was computed.
Definition CameraPose.h:228
static std::string translatePoseQuality(const PoseQuality poseQuality)
Translates the given pose quality to a string.
const HomogenousMatrix4 & world_T_camera() const
Returns the transformation between camera and world.
Definition CameraPose.h:208
EstimatedMotion
Definition of different types of estimated motion.
Definition CameraPose.h:70
@ EM_STATIONARY
The camera is stationary (not moving).
Definition CameraPose.h:74
bool operator==(const CameraPose &right) const =default
Returns whether two camera poses are identical.
EstimatedMotion estimatedMotion_
The estimated motion type of the camera.
Definition CameraPose.h:187
PoseQuality poseQuality_
The quality of the pose.
Definition CameraPose.h:184
bool isValid() const
Returns whether this camera pose is valid.
Definition CameraPose.h:238
PoseQuality poseQuality() const
Returns the quality of this pose.
Definition CameraPose.h:218
void setMapVersion(const Index32 mapVersion)
Sets the version of the map used when this pose was computed.
Definition CameraPose.h:233
EstimatedMotion estimatedMotion() const
Returns the estimated motion type of the camera.
Definition CameraPose.h:223
PoseQuality
Definition of the quality of a camera pose.
Definition CameraPose.h:55
@ PQ_INVALID
The pose is invalid.
Definition CameraPose.h:57
@ PQ_MEDIUM
The pose has a medium quality as it is based on a medium number of feature correspondences.
Definition CameraPose.h:61
@ PQ_LOW
The pose has a low quality as it is based on few feature correspondences.
Definition CameraPose.h:59
static EstimatedMotion motionFromOpticalFlow(const Scalar *imagePointSqrDistances, const size_t size, const unsigned int width, const unsigned int height)
Determines the estimated motion type from optical flow data.
CameraPose()=default
Creates a new invalid camera pose.
This class implements a container for camera poses.
Definition CameraPoses.h:32
uint32_t Index32
Definition of a 32 bit index value.
Definition Base.h:84
float Scalar
Definition of a scalar type.
Definition Math.h:129
std::shared_ptr< CameraPose > SharedCameraPose
Definition of a shared pointer holding a CameraPose object.
Definition CameraPose.h:36
The namespace covering the entire Ocean framework.
Definition Accessor.h:15