Ocean
Loading...
Searching...
No Matches
NonLinearOptimizationPose.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_GEOMETRY_NON_LINEAR_OPTIMIZATION_POSE_H
9#define META_OCEAN_GEOMETRY_NON_LINEAR_OPTIMIZATION_POSE_H
10
14
18
19namespace Ocean
20{
21
22namespace Geometry
23{
24
25/**
26 * This class implements non linear optimization algorithms for camera poses.
27 * @ingroup geometry
28 */
29class OCEAN_GEOMETRY_EXPORT NonLinearOptimizationPose : protected NonLinearOptimization
30{
31 protected:
32
33 /**
34 * Forward declaration of a class implementing a provider allowing to optimize a camera pose.
35 */
36 class PoseOptimizationProvider;
37
38 /**
39 * Forward declaration of a class implementing an advanced provider allowing to optimize any camera pose.
40 */
41 class AdvancedAnyCameraPoseOptimizationProvider;
42
43 /**
44 * Forward declaration of a class implementing a provider allowing to optimize a camera pose together with a zoom factor.
45 */
46 class PoseZoomOptimizationProvider;
47
48 public:
49
50 /**
51 * Minimizes the projection error of a given 6DOF pose holding orientation and translation parameters for any camera.
52 * The given 6DOF pose is a standard extrinsic camera matrix.<br>
53 * @param anyCamera The camera profile defining the projection, must be valid
54 * @param world_T_camera 6DOF pose to minimized the projection error for, must be valid
55 * @param objectPoints 3D object points to be projected into the camera plane
56 * @param imagePoints 2D image points corresponding to the object points, the image points may be distorted or undistorted depending on the usage of the distortImagePoints state
57 * @param world_T_optimizedCamera Resulting optimized 6DOF pose
58 * @param iterations Number of iterations to be applied at most, if no convergence can be reached, with range [1, infinity)
59 * @param estimator Robust error estimator to be used
60 * @param lambda Initial Levenberg-Marquardt damping value which may be changed after each iteration using the damping factor, with range [0, infinity)
61 * @param lambdaFactor Levenberg-Marquardt damping factor to be applied to the damping value, with range [1, infinity)
62 * @param initialError Optional resulting averaged pixel error for the given initial parameters, in relation to the defined estimator
63 * @param finalError Optional resulting averaged pixel error for the final optimized parameters, in relation to the defined estimator
64 * @param intermediateRobustErrors Optional resulting averaged robust pixel errors for intermediate optimization iterations
65 * @param gravityConstraints Optional gravity constraints to force the optimization to create a camera pose aligned with gravity, nullptr to avoid any gravity alignment
66 * @return True, if the optimization succeeded
67 * @see optimizePoseIF().
68 */
69 static inline 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);
70
71 /**
72 * Minimizes the projection error of a given 6-DOF camera pose.
73 * Beware: There is another optimizePose() function with almost identical functionality/parameter layout.<br>
74 * However, this function here supports covariance parameters and thus creates a bigger binary footprint.
75 * @param camera The camera profile defining the projection, must be valid
76 * @param world_T_camera The camera pose to optimized, transforming camera points to world points, with default camera pointing towards the negative z-space with y-axis upwards, must be valid
77 * @param objectPoints 3D object points to be projected into the camera plane
78 * @param imagePoints 2D image points corresponding to the object points, the image points may be distorted or undistorted depending on the usage of the distortImagePoints state
79 * @param world_T_optimizedCamera The resulting optimized 6-DOF camera pose, transforming camera points to world points, with default camera pointing towards the negative z-space with y-axis upwards, must be valid
80 * @param iterations Number of iterations to be applied at most, if no convergence can be reached, with range [1, infinity)
81 * @param estimator Robust error estimator to be used
82 * @param lambda Initial Levenberg-Marquardt damping value which may be changed after each iteration using the damping factor, with range [0, infinity)
83 * @param lambdaFactor Levenberg-Marquardt damping factor to be applied to the damping value, with range [1, infinity)
84 * @param initialError Optional resulting averaged pixel error for the given initial parameters, in relation to the defined estimator, nullptr to avoid the usage of the return value
85 * @param finalError Optional resulting averaged pixel error for the final optimized parameters, in relation to the defined estimator, nullptr to avoid the usage of the return value
86 * @param intermediateRobustErrors Optional resulting averaged robust pixel errors for intermediate optimization iterations
87 * @param invertedCovariances Optional 2x2 inverted covariance matrices which represent the uncertainties of the image points, one for each image point (a (2*n)x2 matrix)
88 * @param gravityConstraints Optional gravity constraint to force the optimization to create a camera pose aligned with gravity, nullptr to avoid any gravity alignment
89 * @return True, if the optimization succeeded
90 * @see optimizePoseIF().
91 */
92 static inline bool optimizePose(const AnyCamera& camera, const HomogenousMatrix4& world_T_camera, const ConstIndexedAccessor<Vector3>& objectPoints, const ConstIndexedAccessor<Vector2>& imagePoints, HomogenousMatrix4& world_T_optimizedCamera, const unsigned int iterations, const Estimator::EstimatorType estimator, Scalar lambda, const Scalar lambdaFactor, Scalar* initialError, Scalar* finalError, Scalars* intermediateRobustErrors, const Matrix* invertedCovariances, const GravityConstraints* gravityConstraints);
93
94 /**
95 * Deprecated.
96 *
97 * Minimizes the projection error of a given 6DOF pose holding orientation and translation parameters.
98 * The given 6DOF pose is a standard extrinsic camera matrix.<br>
99 * Beware: There is another optimizePose() function with almost identical functionality/parameter layout.<br>
100 * However, this function here supports covariance parameters and thus creates a bigger binary footprint.
101 * @param pinholeCamera The pinhole camera object defining the projection between 3D object points and 2D image points
102 * @param world_T_camera 6DOF pose to minimized the projection error for, must be valid
103 * @param objectPoints 3D object points to be projected into the camera plane
104 * @param imagePoints 2D image points corresponding to the object points, the image points may be distorted or undistorted depending on the usage of the distortImagePoints state
105 * @param distortImagePoints True, to force the usage of the distortion parameters of the given camera object to distort the projected 2D image points before error determination
106 * @param world_T_optimizedCamera Resulting optimized 6DOF pose
107 * @param iterations Number of iterations to be applied at most, if no convergence can be reached, with range [1, infinity)
108 * @param estimator Robust error estimator to be used
109 * @param lambda Initial Levenberg-Marquardt damping value which may be changed after each iteration using the damping factor, with range [0, infinity)
110 * @param lambdaFactor Levenberg-Marquardt damping factor to be applied to the damping value, with range [1, infinity)
111 * @param initialError Optional resulting averaged pixel error for the given initial parameters, in relation to the defined estimator, nullptr to avoid the usage of the return value
112 * @param finalError Optional resulting averaged pixel error for the final optimized parameters, in relation to the defined estimator, nullptr to avoid the usage of the return value
113 * @param invertedCovariances Set of 2x2 inverted covariance matrices that represent the uncertainties of the image points (a 2*n x 2 matrix)
114 * @return True, if the optimization succeeded
115 * @see optimizePoseIF().
116 */
117 static inline bool optimizePose(const PinholeCamera& pinholeCamera, const HomogenousMatrix4& world_T_camera, const ConstIndexedAccessor<Vector3>& objectPoints, const ConstIndexedAccessor<Vector2>& imagePoints, const bool distortImagePoints, HomogenousMatrix4& world_T_optimizedCamera, const unsigned int iterations, const Estimator::EstimatorType estimator, Scalar lambda, const Scalar lambdaFactor, Scalar* initialError, Scalar* finalError, const Matrix* invertedCovariances);
118
119 /**
120 * Minimizes the projection error of a given 6DOF pose holding orientation and translation parameters together with a flexible zoom.
121 * The given 6DOF pose is a standard extrinsic camera matrix.<br>
122 * @param pinholeCamera The pinhole camera object defining the projection between 3D object points and 2D image points
123 * @param world_T_camera 6DOF pose to minimized the projection error for, must be valid
124 * @param zoom The scalar zoom factor matching to the given pose, with range (0, infinity)
125 * @param objectPoints 3D object points to be projected into the camera plane
126 * @param imagePoints 2D image points corresponding to the object points, the image points may be distorted or undistorted depending on the usage of the distortImagePoints state
127 * @param distortImagePoints True, to force the usage of the distortion parameters of the given camera object to distort the projected 2D image points before error determination
128 * @param world_T_optimizedCamera Resulting optimized 6DOF pose
129 * @param optimizedZoom Resulting optimized zoom factor matching to the resulting optimized pose, with range (0, infinity)
130 * @param iterations Number of iterations to be applied at most, if no convergence can be reached, with range [1, infinity)
131 * @param estimator Robust error estimator to be used
132 * @param lambda Initial Levenberg-Marquardt damping value which may be changed after each iteration using the damping factor, with range [0, infinity)
133 * @param lambdaFactor Levenberg-Marquardt damping factor to be applied to the damping value, with range [1, infinity)
134 * @param initialError Optional resulting averaged pixel error for the given initial parameters, in relation to the defined estimator
135 * @param finalError Optional resulting averaged pixel error for the final optimized parameters, in relation to the defined estimator
136 * @param invertedCovariances Optional set of 2x2 inverted covariance matrices that represent the uncertainties of the image points (a 2*n x 2 matrix)
137 * @return True, if the optimization succeeded
138 * @see optimizePoseIF().
139 */
140 static inline bool optimizePoseZoom(const PinholeCamera& pinholeCamera, const HomogenousMatrix4& world_T_camera, const Scalar zoom, const ConstIndexedAccessor<Vector3>& objectPoints, const ConstIndexedAccessor<Vector2>& imagePoints, const bool distortImagePoints, HomogenousMatrix4& world_T_optimizedCamera, Scalar& optimizedZoom, 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, const Matrix* invertedCovariances = nullptr);
141
142 /**
143 * Minimizes the projection error of a given inverted and flipped 6DOF pose holding orientation and translation parameters for any camera.
144 * Beware: The given inverted and flipped 6DOF pose is not equivalent to a standard extrinsic camera matrix.
145 * @param anyCamera The camera profile defining the projection, must be valid
146 * @param flippedCamera_T_world 6DOF pose to minimized the projection error for (inverted and flipped), must be valid
147 * @param objectPoints 3D object points to be projected into the camera plane
148 * @param imagePoints 2D image points corresponding to the object points, the image points may be distorted or undistorted depending on the usage of the distortImagePoints state
149 * @param optimizedFlippedCamera_T_world Resulting optimized 6DOF pose (inverted and flipped)
150 * @param iterations Number of iterations to be applied at most, if no convergence can be reached, with range [1, infinity)
151 * @param estimator Robust error estimator to be used
152 * @param lambda Initial Levenberg-Marquardt damping value which may be changed after each iteration using the damping factor, with range [0, infinity)
153 * @param lambdaFactor Levenberg-Marquardt damping factor to be applied to the damping value, with range [1, infinity)
154 * @param initialError Optional resulting averaged pixel error for the given initial parameters, in relation to the defined estimator
155 * @param finalError Optional resulting averaged pixel error for the final optimized parameters, in relation to the defined estimator
156 * @param intermediateRobustErrors Optional resulting averaged robust pixel errors for intermediate optimization iterations
157 * @param gravityConstraints Optional gravity constraints to force the optimization to create a camera pose aligned with gravity, nullptr to avoid any gravity alignment
158 * @return True, if succeeded
159 * @see optimizePose().
160 */
161 static bool optimizePoseIF(const AnyCamera& anyCamera, const HomogenousMatrix4& flippedCamera_T_world, const ConstIndexedAccessor<Vector3>& objectPoints, const ConstIndexedAccessor<Vector2>& imagePoints, HomogenousMatrix4& optimizedFlippedCamera_T_world, 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);
162
163 /**
164 * Minimizes the projection error of a given 6-DOF camera pose.
165 * Beware: There is another optimizePose() function with almost identical functionality/parameter layout.<br>
166 * However, this function here supports covariance parameters and thus creates a bigger binary footprint.
167 * @param camera The camera profile defining the projection, must be valid
168 * @param flippedCamera_T_world The inverted and flipped camera pose to optimized, transforming world points to flipped camera points, with default camera pointing towards the positive z-space with y-axis downwards, must be valid
169 * @param objectPoints 3D object points to be projected into the camera plane
170 * @param imagePoints 2D image points corresponding to the object points, the image points may be distorted or undistorted depending on the usage of the distortImagePoints state
171 * @param optimizedFlippedCamera_T_world The resulting optimized inverted and flipped camera pose, transforming world points to flipped camera points, with default camera pointing towards the positive z-space with y-axis downwards, must be valid
172 * @param iterations Number of iterations to be applied at most, if no convergence can be reached, with range [1, infinity)
173 * @param estimator Robust error estimator to be used
174 * @param lambda Initial Levenberg-Marquardt damping value which may be changed after each iteration using the damping factor, with range [0, infinity)
175 * @param lambdaFactor Levenberg-Marquardt damping factor to be applied to the damping value, with range [1, infinity)
176 * @param initialError Optional resulting averaged pixel error for the given initial parameters, in relation to the defined estimator, nullptr to avoid the usage of the return value
177 * @param finalError Optional resulting averaged pixel error for the final optimized parameters, in relation to the defined estimator, nullptr to avoid the usage of the return value
178 * @param intermediateRobustErrors Optional resulting averaged robust pixel errors for intermediate optimization iterations
179 * @param invertedCovariances Optional 2x2 inverted covariance matrices which represent the uncertainties of the image points, one for each image point (a (2*n)x2 matrix)
180 * @param gravityConstraints Optional gravity constraints to force the optimization to create a camera pose aligned with gravity, nullptr to avoid any gravity alignment
181 * @return True, if the optimization succeeded
182 * @see optimizePose().
183 */
184 static bool optimizePoseIF(const AnyCamera& camera, const HomogenousMatrix4& flippedCamera_T_world, const ConstIndexedAccessor<Vector3>& objectPoints, const ConstIndexedAccessor<Vector2>& imagePoints, HomogenousMatrix4& optimizedFlippedCamera_T_world, const unsigned int iterations, const Estimator::EstimatorType estimator, Scalar lambda, const Scalar lambdaFactor, Scalar* initialError, Scalar* finalError, Scalars* intermediateRobustErrors, const Matrix* invertedCovariances, const GravityConstraints* gravityConstraints);
185
186 /**
187 * Deprecated.
188 *
189 * Minimizes the projection error of a given inverted and flipped 6DOF pose holding orientation and translation parameters.
190 * Beware: The given inverted and flipped 6DOF pose is not equivalent to a standard extrinsic camera matrix.<br>
191 * Beware: There is another optimizePoseIF() function with almost identical functionality/parameter layout.<br>
192 * However, this function here supports covariance parameters and thus creates a bigger binary footprint.
193 * @param pinholeCamera The pinhole camera object defining the projection between 3D object points and 2D image points
194 * @param flippedCamera_T_world 6DOF pose to minimized the projection error for (inverted and flipped), must be valid
195 * @param objectPoints 3D object points to be projected into the camera plane
196 * @param imagePoints 2D image points corresponding to the object points, the image points may be distorted or undistorted depending on the usage of the distortImagePoints state
197 * @param distortImagePoints True, to force the usage of the distortion parameters of the given camera object to distort the projected 2D image points before error determination
198 * @param optimizedInvertedFlippedPose Resulting optimized 6DOF pose (inverted and flipped)
199 * @param iterations Number of iterations to be applied at most, if no convergence can be reached, with range [1, infinity)
200 * @param estimator Robust error estimator to be used
201 * @param lambda Initial Levenberg-Marquardt damping value which may be changed after each iteration using the damping factor, with range [0, infinity)
202 * @param lambdaFactor Levenberg-Marquardt damping factor to be applied to the damping value, with range [1, infinity)
203 * @param initialError Optional resulting averaged pixel error for the given initial parameters, in relation to the defined estimator, nullptr to avoid the usage of the return value
204 * @param finalError Optional resulting averaged pixel error for the final optimized parameters, in relation to the defined estimator, nullptr to avoid the usage of the return value
205 * @param invertedCovariances Optional set of 2x2 inverted covariance matrices that represent the uncertainties of the image points (a 2*n x 2 matrix)
206 * @return True, if succeeded
207 * @see optimizePose().
208 */
209 static bool optimizePoseIF(const PinholeCamera& pinholeCamera, const HomogenousMatrix4& flippedCamera_T_world, const ConstIndexedAccessor<Vector3>& objectPoints, const ConstIndexedAccessor<Vector2>& imagePoints, const bool distortImagePoints, HomogenousMatrix4& optimizedInvertedFlippedPose, const unsigned int iterations, const Estimator::EstimatorType estimator, Scalar lambda, const Scalar lambdaFactor, Scalar* initialError, Scalar* finalError, const Matrix* invertedCovariances);
210
211 /**
212 * Minimizes the projection error of a given inverted and flipped 6DOF pose holding orientation and translation parameters together with a flexible zoom.
213 * Beware: The given inverted and flipped 6DOF pose is not equivalent to a standard extrinsic camera matrix.<br>
214 * @param pinholeCamera The pinhole camera object defining the projection between 3D object points and 2D image points
215 * @param flippedCamera_T_world 6DOF pose to minimized the projection error for (inverted and flipped), must be valid
216 * @param zoom The scalar zoom factor matching to the given pose, with range (0, infinity)
217 * @param objectPoints 3D object points to be projected into the camera plane
218 * @param imagePoints 2D image points corresponding to the object points, the image points may be distorted or undistorted depending on the usage of the distortImagePoints state
219 * @param distortImagePoints True, to force the usage of the distortion parameters of the given camera object to distort the projected 2D image points before error determination
220 * @param optimizedInvertedFlippedPose Resulting optimized 6DOF pose (inverted and flipped)
221 * @param optimizedZoom Resulting optimized zoom factor matching to the resulting optimized pose, with range (0, infinity)
222 * @param iterations Number of iterations to be applied at most, if no convergence can be reached, with range [1, infinity)
223 * @param estimator Robust error estimator to be used
224 * @param lambda Initial Levenberg-Marquardt damping value which may be changed after each iteration using the damping factor, with range [0, infinity)
225 * @param lambdaFactor Levenberg-Marquardt damping factor to be applied to the damping value, with range [1, infinity)
226 * @param initialError Optional resulting averaged pixel error for the given initial parameters, in relation to the defined estimator
227 * @param finalError Optional resulting averaged pixel error for the final optimized parameters, in relation to the defined estimator
228 * @param invertedCovariances Optional set of 2x2 inverted covariance matrices that represent the uncertainties of the image points (a 2*n x 2 matrix)
229 * @return True, if succeeded
230 * @see optimizePose().
231 */
232 static bool optimizePoseZoomIF(const PinholeCamera& pinholeCamera, const HomogenousMatrix4& flippedCamera_T_world, const Scalar zoom, const ConstIndexedAccessor<Vector3>& objectPoints, const ConstIndexedAccessor<Vector2>& imagePoints, const bool distortImagePoints, HomogenousMatrix4& optimizedInvertedFlippedPose, Scalar& optimizedZoom, 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, const Matrix* invertedCovariances = nullptr);
233};
234
235inline bool NonLinearOptimizationPose::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, const Estimator::EstimatorType estimator, Scalar lambda, const Scalar lambdaFactor, Scalar* initialError, Scalar* finalError, Scalars* intermediateRobustErrors, const GravityConstraints* gravityConstraints)
236{
237 ocean_assert(anyCamera.isValid());
238 ocean_assert(world_T_camera.isValid());
239 ocean_assert(objectPoints.size() >= 3);
240 ocean_assert(objectPoints.size() == imagePoints.size());
241
242 const HomogenousMatrix4 flippedCamera_T_world(Camera::standard2InvertedFlipped(world_T_camera));
243
244 HomogenousMatrix4 optimizedFlippedCamera_T_world;
245 if (!optimizePoseIF(anyCamera, flippedCamera_T_world, objectPoints, imagePoints, optimizedFlippedCamera_T_world, iterations, estimator, lambda, lambdaFactor, initialError, finalError, intermediateRobustErrors, gravityConstraints))
246 {
247 return false;
248 }
249
250 world_T_optimizedCamera = Camera::invertedFlipped2Standard(optimizedFlippedCamera_T_world);
251 return true;
252}
253
254inline bool NonLinearOptimizationPose::optimizePose(const AnyCamera& camera, const HomogenousMatrix4& world_T_camera, const ConstIndexedAccessor<Vector3>& objectPoints, const ConstIndexedAccessor<Vector2>& imagePoints, HomogenousMatrix4& world_T_optimizedCamera, const unsigned int iterations, const Estimator::EstimatorType estimator, Scalar lambda, const Scalar lambdaFactor, Scalar* initialError, Scalar* finalError, Scalars* intermediateRobustErrors, const Matrix* invertedCovariances, const GravityConstraints* gravityConstraints)
255{
256 ocean_assert(camera.isValid());
257 ocean_assert(world_T_camera.isValid());
258
259 ocean_assert(objectPoints.size() >= 3u);
260 ocean_assert(objectPoints.size() == imagePoints.size());
261
262 const HomogenousMatrix4 flippedCamera_T_world(PinholeCamera::standard2InvertedFlipped(world_T_camera));
263
264 HomogenousMatrix4 optimizedFlippedCamera_T_world(false);
265 if (!optimizePoseIF(camera, flippedCamera_T_world, objectPoints, imagePoints, optimizedFlippedCamera_T_world, iterations, estimator, lambda, lambdaFactor, initialError, finalError, intermediateRobustErrors, invertedCovariances, gravityConstraints))
266 {
267 return false;
268 }
269
270 world_T_optimizedCamera = PinholeCamera::invertedFlipped2Standard(optimizedFlippedCamera_T_world);
271 return true;
272}
273
274inline bool NonLinearOptimizationPose::optimizePose(const PinholeCamera& pinholeCamera, const HomogenousMatrix4& world_T_camera, const ConstIndexedAccessor<Vector3>& objectPoints, const ConstIndexedAccessor<Vector2>& imagePoints, const bool distortImagePoints, HomogenousMatrix4& world_T_optimizedCamera, const unsigned int iterations, const Estimator::EstimatorType estimator, Scalar lambda, const Scalar lambdaFactor, Scalar* initialError, Scalar* finalError, const Matrix* invertedCovariances)
275{
276 const AnyCameraPinhole anyCamera(PinholeCamera(pinholeCamera, distortImagePoints));
277
278 constexpr Scalars* intermediateRobustErrors = nullptr;
279 constexpr const GravityConstraints* gravityConstraints = nullptr;
280
281 return optimizePose(anyCamera, world_T_camera, objectPoints, imagePoints, world_T_optimizedCamera, iterations, estimator, lambda, lambdaFactor, initialError, finalError, intermediateRobustErrors, invertedCovariances, gravityConstraints);
282}
283
284inline bool NonLinearOptimizationPose::optimizePoseZoom(const PinholeCamera& pinholeCamera, const HomogenousMatrix4& world_T_camera, const Scalar zoom, const ConstIndexedAccessor<Vector3>& objectPoints, const ConstIndexedAccessor<Vector2>& imagePoints, const bool distortImagePoints, HomogenousMatrix4& world_T_optimizedCamera, Scalar& optimizedZoom, const unsigned int iterations, const Estimator::EstimatorType estimator, Scalar lambda, const Scalar lambdaFactor, Scalar* initialError, Scalar* finalError, const Matrix* invertedCovariances)
285{
286 ocean_assert(world_T_camera.isValid() && zoom > Numeric::eps());
287 ocean_assert(objectPoints.size() >= 3u);
288 ocean_assert(objectPoints.size() == imagePoints.size());
289
290 const HomogenousMatrix4 flippedCamera_T_world(PinholeCamera::standard2InvertedFlipped(world_T_camera));
291
292 HomogenousMatrix4 optimizedInvertedFlippedPose;
293 if (!optimizePoseZoomIF(pinholeCamera, flippedCamera_T_world, zoom, objectPoints, imagePoints, distortImagePoints, optimizedInvertedFlippedPose, optimizedZoom, iterations, estimator, lambda, lambdaFactor, initialError, finalError, invertedCovariances))
294 {
295 return false;
296 }
297
298 world_T_optimizedCamera = PinholeCamera::invertedFlipped2Standard(optimizedInvertedFlippedPose);
299 return true;
300}
301
302}
303
304}
305
306#endif // META_OCEAN_GEOMETRY_NON_LINEAR_OPTIMIZATION_POSE_H
virtual size_t size() const =0
Returns the number of accessible elements of this accessor object.
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 a specialized AnyCamera object wrapping the actual camera model.
Definition AnyCamera.h:630
static HomogenousMatrixT4< U > standard2InvertedFlipped(const HomogenousMatrixT4< U > &world_T_camera)
Transforms a standard homogenous 4x4 viewing (extrinsic camera) matrix into an inverted and flipped c...
Definition Camera.h:778
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
This class implements a base class for all indexed-based accessors allowing a constant reference acce...
Definition Accessor.h:241
EstimatorType
Definition of individual robust estimator types.
Definition Estimator.h:34
This class implements a container allowing to define gravity constraints during e....
Definition GravityConstraints.h:63
This class implements the basic functions for least square or robust optimization algorithms for non ...
Definition NonLinearOptimization.h:33
This class implements non linear optimization algorithms for camera poses.
Definition NonLinearOptimizationPose.h:30
static bool optimizePoseZoom(const PinholeCamera &pinholeCamera, const HomogenousMatrix4 &world_T_camera, const Scalar zoom, const ConstIndexedAccessor< Vector3 > &objectPoints, const ConstIndexedAccessor< Vector2 > &imagePoints, const bool distortImagePoints, HomogenousMatrix4 &world_T_optimizedCamera, Scalar &optimizedZoom, 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, const Matrix *invertedCovariances=nullptr)
Minimizes the projection error of a given 6DOF pose holding orientation and translation parameters to...
Definition NonLinearOptimizationPose.h:284
static bool optimizePoseIF(const AnyCamera &camera, const HomogenousMatrix4 &flippedCamera_T_world, const ConstIndexedAccessor< Vector3 > &objectPoints, const ConstIndexedAccessor< Vector2 > &imagePoints, HomogenousMatrix4 &optimizedFlippedCamera_T_world, const unsigned int iterations, const Estimator::EstimatorType estimator, Scalar lambda, const Scalar lambdaFactor, Scalar *initialError, Scalar *finalError, Scalars *intermediateRobustErrors, const Matrix *invertedCovariances, const GravityConstraints *gravityConstraints)
Minimizes the projection error of a given 6-DOF camera pose.
static bool optimizePoseIF(const AnyCamera &anyCamera, const HomogenousMatrix4 &flippedCamera_T_world, const ConstIndexedAccessor< Vector3 > &objectPoints, const ConstIndexedAccessor< Vector2 > &imagePoints, HomogenousMatrix4 &optimizedFlippedCamera_T_world, 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 inverted and flipped 6DOF pose holding orientation and tran...
static bool optimizePoseZoomIF(const PinholeCamera &pinholeCamera, const HomogenousMatrix4 &flippedCamera_T_world, const Scalar zoom, const ConstIndexedAccessor< Vector3 > &objectPoints, const ConstIndexedAccessor< Vector2 > &imagePoints, const bool distortImagePoints, HomogenousMatrix4 &optimizedInvertedFlippedPose, Scalar &optimizedZoom, 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, const Matrix *invertedCovariances=nullptr)
Minimizes the projection error of a given inverted and flipped 6DOF pose holding orientation and tran...
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
static bool optimizePoseIF(const PinholeCamera &pinholeCamera, const HomogenousMatrix4 &flippedCamera_T_world, const ConstIndexedAccessor< Vector3 > &objectPoints, const ConstIndexedAccessor< Vector2 > &imagePoints, const bool distortImagePoints, HomogenousMatrix4 &optimizedInvertedFlippedPose, const unsigned int iterations, const Estimator::EstimatorType estimator, Scalar lambda, const Scalar lambdaFactor, Scalar *initialError, Scalar *finalError, const Matrix *invertedCovariances)
Deprecated.
bool isValid() const
Returns whether this matrix is a valid homogeneous transformation.
Definition HomogenousMatrix4.h:1806
static constexpr T eps()
Returns a small epsilon.
PinholeCameraT< Scalar > PinholeCamera
Definition of an pinhole camera object with Scalar precision.
Definition PinholeCamera.h:39
float Scalar
Definition of a scalar type.
Definition Math.h:129
std::vector< Scalar > Scalars
Definition of a vector holding Scalar objects.
Definition Math.h:145
The namespace covering the entire Ocean framework.
Definition Accessor.h:15