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 a pinhole camera pose.
40 */
41 class AdvancedPinholeCameraPoseOptimizationProvider;
42
43 /**
44 * Forward declaration of a class implementing an advanced provider allowing to optimize any camera pose.
45 */
46 class AdvancedAnyCameraPoseOptimizationProvider;
47
48 /**
49 * Forward declaration of a class implementing a provider allowing to optimize a camera pose together with a zoom factor.
50 */
51 class PoseZoomOptimizationProvider;
52
53 public:
54
55 /**
56 * Deprecated.
57 *
58 * Minimizes the projection error of a given 6DOF pose holding orientation and translation parameters for a pinhole camera.
59 * The given 6DOF pose is a standard extrinsic camera matrix.<br>
60 * Beware: There is another optimizePose() function with almost identical functionality/parameter layout.<br>
61 * However, this function here does not support covariance parameters and thus creates a smaller binary footprint.<br>
62 * In case binary size matters, try to use this function only, and do not mix the usage of both options.
63 * @param pinholeCamera The pinhole camera object defining the projection between 3D object points and 2D image points, must be valid
64 * @param world_T_camera 6DOF pose to minimized the projection error for, must be valid
65 * @param objectPoints 3D object points to be projected into the camera plane
66 * @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
67 * @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
68 * @param world_T_optimizedCamera Resulting optimized 6DOF pose
69 * @param iterations Number of iterations to be applied at most, if no convergence can be reached, with range [1, infinity)
70 * @param estimator Robust error estimator to be used
71 * @param lambda Initial Levenberg-Marquardt damping value which may be changed after each iteration using the damping factor, with range [0, infinity)
72 * @param lambdaFactor Levenberg-Marquardt damping factor to be applied to the damping value, with range [1, infinity)
73 * @param initialError Optional resulting averaged pixel error for the given initial parameters, in relation to the defined estimator
74 * @param finalError Optional resulting averaged pixel error for the final optimized parameters, in relation to the defined estimator
75 * @return True, if the optimization succeeded
76 * @see optimizePoseIF().
77 */
78 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 = 20u, const Estimator::EstimatorType estimator = Estimator::ET_SQUARE, Scalar lambda = Scalar(0.001), const Scalar lambdaFactor = 10, Scalar* initialError = nullptr, Scalar* finalError = nullptr);
79
80 /**
81 * Minimizes the projection error of a given 6DOF pose holding orientation and translation parameters for any camera.
82 * The given 6DOF pose is a standard extrinsic camera matrix.<br>
83 * @param anyCamera The camera profile defining the projection, must be valid
84 * @param world_T_camera 6DOF pose to minimized the projection error for, must be valid
85 * @param objectPoints 3D object points to be projected into the camera plane
86 * @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
87 * @param world_T_optimizedCamera Resulting optimized 6DOF pose
88 * @param iterations Number of iterations to be applied at most, if no convergence can be reached, with range [1, infinity)
89 * @param estimator Robust error estimator to be used
90 * @param lambda Initial Levenberg-Marquardt damping value which may be changed after each iteration using the damping factor, with range [0, infinity)
91 * @param lambdaFactor Levenberg-Marquardt damping factor to be applied to the damping value, with range [1, infinity)
92 * @param initialError Optional resulting averaged pixel error for the given initial parameters, in relation to the defined estimator
93 * @param finalError Optional resulting averaged pixel error for the final optimized parameters, in relation to the defined estimator
94 * @param intermediateRobustErrors Optional resulting averaged robust pixel errors for intermediate optimization iterations
95 * @param gravityConstraints Optional gravity constraints to force the optimization to create a camera pose aligned with gravity, nullptr to avoid any gravity alignment
96 * @return True, if the optimization succeeded
97 * @see optimizePoseIF().
98 */
99 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);
100
101 /**
102 * Minimizes the projection error of a given 6-DOF camera pose.
103 * Beware: There is another optimizePose() function with almost identical functionality/parameter layout.<br>
104 * However, this function here supports covariance parameters and thus creates a bigger binary footprint.
105 * @param camera The camera profile defining the projection, must be valid
106 * @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
107 * @param objectPoints 3D object points to be projected into the camera plane
108 * @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
109 * @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
110 * @param iterations Number of iterations to be applied at most, if no convergence can be reached, with range [1, infinity)
111 * @param estimator Robust error estimator to be used
112 * @param lambda Initial Levenberg-Marquardt damping value which may be changed after each iteration using the damping factor, with range [0, infinity)
113 * @param lambdaFactor Levenberg-Marquardt damping factor to be applied to the damping value, with range [1, infinity)
114 * @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
115 * @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
116 * @param intermediateRobustErrors Optional resulting averaged robust pixel errors for intermediate optimization iterations
117 * @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)
118 * @param gravityConstraints Optional gravity constraint to force the optimization to create a camera pose aligned with gravity, nullptr to avoid any gravity alignment
119 * @return True, if the optimization succeeded
120 * @see optimizePoseIF().
121 */
122 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);
123
124 /**
125 * Deprecated.
126 *
127 * Minimizes the projection error of a given 6DOF pose holding orientation and translation parameters.
128 * The given 6DOF pose is a standard extrinsic camera matrix.<br>
129 * Beware: There is another optimizePose() function with almost identical functionality/parameter layout.<br>
130 * However, this function here supports covariance parameters and thus creates a bigger binary footprint.
131 * @param pinholeCamera The pinhole camera object defining the projection between 3D object points and 2D image points
132 * @param world_T_camera 6DOF pose to minimized the projection error for, must be valid
133 * @param objectPoints 3D object points to be projected into the camera plane
134 * @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
135 * @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
136 * @param world_T_optimizedCamera Resulting optimized 6DOF pose
137 * @param iterations Number of iterations to be applied at most, if no convergence can be reached, with range [1, infinity)
138 * @param estimator Robust error estimator to be used
139 * @param lambda Initial Levenberg-Marquardt damping value which may be changed after each iteration using the damping factor, with range [0, infinity)
140 * @param lambdaFactor Levenberg-Marquardt damping factor to be applied to the damping value, with range [1, infinity)
141 * @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
142 * @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
143 * @param invertedCovariances Set of 2x2 inverted covariance matrices that represent the uncertainties of the image points (a 2*n x 2 matrix)
144 * @return True, if the optimization succeeded
145 * @see optimizePoseIF().
146 */
147 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);
148
149 /**
150 * Minimizes the projection error of a given 6DOF pose holding orientation and translation parameters together with a flexible zoom.
151 * The given 6DOF pose is a standard extrinsic camera matrix.<br>
152 * @param pinholeCamera The pinhole camera object defining the projection between 3D object points and 2D image points
153 * @param world_T_camera 6DOF pose to minimized the projection error for, must be valid
154 * @param zoom The scalar zoom factor matching to the given pose, with range (0, infinity)
155 * @param objectPoints 3D object points to be projected into the camera plane
156 * @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
157 * @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
158 * @param world_T_optimizedCamera Resulting optimized 6DOF pose
159 * @param optimizedZoom Resulting optimized zoom factor matching to the resulting optimized pose, with range (0, infinity)
160 * @param iterations Number of iterations to be applied at most, if no convergence can be reached, with range [1, infinity)
161 * @param estimator Robust error estimator to be used
162 * @param lambda Initial Levenberg-Marquardt damping value which may be changed after each iteration using the damping factor, with range [0, infinity)
163 * @param lambdaFactor Levenberg-Marquardt damping factor to be applied to the damping value, with range [1, infinity)
164 * @param initialError Optional resulting averaged pixel error for the given initial parameters, in relation to the defined estimator
165 * @param finalError Optional resulting averaged pixel error for the final optimized parameters, in relation to the defined estimator
166 * @param invertedCovariances Optional set of 2x2 inverted covariance matrices that represent the uncertainties of the image points (a 2*n x 2 matrix)
167 * @return True, if the optimization succeeded
168 * @see optimizePoseIF().
169 */
170 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);
171
172 /**
173 * Deprecated.
174 *
175 * Minimizes the projection error of a given inverted and flipped 6DOF pose holding orientation and translation parameters for a pinhole camera.
176 * Beware: The given inverted and flipped 6DOF pose is not equivalent to a standard extrinsic camera matrix.<br>
177 * Beware: There is another optimizePoseIF() function with almost identical functionality/parameter layout.<br>
178 * However, this function here does not support covariance parameters and thus creates a smaller binary footprint.<br>
179 * In case binary size matters, try to use this function only, and do not mix the usage of both options.
180 * @param pinholeCamera The pinhole camera object defining the projection between 3D object points and 2D image points
181 * @param flippedCamera_T_world 6DOF pose to minimized the projection error for (inverted and flipped), must be valid
182 * @param objectPoints 3D object points to be projected into the camera plane
183 * @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
184 * @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
185 * @param optimizedInvertedFlippedPose Resulting optimized 6DOF pose (inverted and flipped)
186 * @param iterations Number of iterations to be applied at most, if no convergence can be reached, with range [1, infinity)
187 * @param estimator Robust error estimator to be used
188 * @param lambda Initial Levenberg-Marquardt damping value which may be changed after each iteration using the damping factor, with range [0, infinity)
189 * @param lambdaFactor Levenberg-Marquardt damping factor to be applied to the damping value, with range [1, infinity)
190 * @param initialError Optional resulting averaged pixel error for the given initial parameters, in relation to the defined estimator
191 * @param finalError Optional resulting averaged pixel error for the final optimized parameters, in relation to the defined estimator
192 * @return True, if succeeded
193 * @see optimizePose().
194 */
195 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 = 20u, const Estimator::EstimatorType estimator = Estimator::ET_SQUARE, Scalar lambda = Scalar(0.001), const Scalar lambdaFactor = 10, Scalar* initialError = nullptr, Scalar* finalError = nullptr);
196
197 /**
198 * Minimizes the projection error of a given inverted and flipped 6DOF pose holding orientation and translation parameters for any camera.
199 * Beware: The given inverted and flipped 6DOF pose is not equivalent to a standard extrinsic camera matrix.
200 * @param anyCamera The camera profile defining the projection, must be valid
201 * @param flippedCamera_T_world 6DOF pose to minimized the projection error for (inverted and flipped), must be valid
202 * @param objectPoints 3D object points to be projected into the camera plane
203 * @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
204 * @param optimizedFlippedCamera_T_world Resulting optimized 6DOF pose (inverted and flipped)
205 * @param iterations Number of iterations to be applied at most, if no convergence can be reached, with range [1, infinity)
206 * @param estimator Robust error estimator to be used
207 * @param lambda Initial Levenberg-Marquardt damping value which may be changed after each iteration using the damping factor, with range [0, infinity)
208 * @param lambdaFactor Levenberg-Marquardt damping factor to be applied to the damping value, with range [1, infinity)
209 * @param initialError Optional resulting averaged pixel error for the given initial parameters, in relation to the defined estimator
210 * @param finalError Optional resulting averaged pixel error for the final optimized parameters, in relation to the defined estimator
211 * @param intermediateRobustErrors Optional resulting averaged robust pixel errors for intermediate optimization iterations
212 * @param gravityConstraints Optional gravity constraints to force the optimization to create a camera pose aligned with gravity, nullptr to avoid any gravity alignment
213 * @return True, if succeeded
214 * @see optimizePose().
215 */
216 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);
217
218 /**
219 * Minimizes the projection error of a given 6-DOF camera pose.
220 * Beware: There is another optimizePose() function with almost identical functionality/parameter layout.<br>
221 * However, this function here supports covariance parameters and thus creates a bigger binary footprint.
222 * @param camera The camera profile defining the projection, must be valid
223 * @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
224 * @param objectPoints 3D object points to be projected into the camera plane
225 * @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
226 * @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
227 * @param iterations Number of iterations to be applied at most, if no convergence can be reached, with range [1, infinity)
228 * @param estimator Robust error estimator to be used
229 * @param lambda Initial Levenberg-Marquardt damping value which may be changed after each iteration using the damping factor, with range [0, infinity)
230 * @param lambdaFactor Levenberg-Marquardt damping factor to be applied to the damping value, with range [1, infinity)
231 * @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
232 * @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
233 * @param intermediateRobustErrors Optional resulting averaged robust pixel errors for intermediate optimization iterations
234 * @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)
235 * @param gravityConstraints Optional gravity constraints to force the optimization to create a camera pose aligned with gravity, nullptr to avoid any gravity alignment
236 * @return True, if the optimization succeeded
237 * @see optimizePose().
238 */
239 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);
240
241 /**
242 * Deprecated.
243 *
244 * Minimizes the projection error of a given inverted and flipped 6DOF pose holding orientation and translation parameters.
245 * Beware: The given inverted and flipped 6DOF pose is not equivalent to a standard extrinsic camera matrix.<br>
246 * Beware: There is another optimizePoseIF() function with almost identical functionality/parameter layout.<br>
247 * However, this function here supports covariance parameters and thus creates a bigger binary footprint.
248 * @param pinholeCamera The pinhole camera object defining the projection between 3D object points and 2D image points
249 * @param flippedCamera_T_world 6DOF pose to minimized the projection error for (inverted and flipped), must be valid
250 * @param objectPoints 3D object points to be projected into the camera plane
251 * @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
252 * @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
253 * @param optimizedInvertedFlippedPose Resulting optimized 6DOF pose (inverted and flipped)
254 * @param iterations Number of iterations to be applied at most, if no convergence can be reached, with range [1, infinity)
255 * @param estimator Robust error estimator to be used
256 * @param lambda Initial Levenberg-Marquardt damping value which may be changed after each iteration using the damping factor, with range [0, infinity)
257 * @param lambdaFactor Levenberg-Marquardt damping factor to be applied to the damping value, with range [1, infinity)
258 * @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
259 * @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
260 * @param invertedCovariances Optional set of 2x2 inverted covariance matrices that represent the uncertainties of the image points (a 2*n x 2 matrix)
261 * @return True, if succeeded
262 * @see optimizePose().
263 */
264 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);
265
266 /**
267 * Minimizes the projection error of a given inverted and flipped 6DOF pose holding orientation and translation parameters together with a flexible zoom.
268 * Beware: The given inverted and flipped 6DOF pose is not equivalent to a standard extrinsic camera matrix.<br>
269 * @param pinholeCamera The pinhole camera object defining the projection between 3D object points and 2D image points
270 * @param flippedCamera_T_world 6DOF pose to minimized the projection error for (inverted and flipped), must be valid
271 * @param zoom The scalar zoom factor matching to the given pose, with range (0, infinity)
272 * @param objectPoints 3D object points to be projected into the camera plane
273 * @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
274 * @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
275 * @param optimizedInvertedFlippedPose Resulting optimized 6DOF pose (inverted and flipped)
276 * @param optimizedZoom Resulting optimized zoom factor matching to the resulting optimized pose, with range (0, infinity)
277 * @param iterations Number of iterations to be applied at most, if no convergence can be reached, with range [1, infinity)
278 * @param estimator Robust error estimator to be used
279 * @param lambda Initial Levenberg-Marquardt damping value which may be changed after each iteration using the damping factor, with range [0, infinity)
280 * @param lambdaFactor Levenberg-Marquardt damping factor to be applied to the damping value, with range [1, infinity)
281 * @param initialError Optional resulting averaged pixel error for the given initial parameters, in relation to the defined estimator
282 * @param finalError Optional resulting averaged pixel error for the final optimized parameters, in relation to the defined estimator
283 * @param invertedCovariances Optional set of 2x2 inverted covariance matrices that represent the uncertainties of the image points (a 2*n x 2 matrix)
284 * @return True, if succeeded
285 * @see optimizePose().
286 */
287 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);
288};
289
290inline 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)
291{
292 ocean_assert(pinholeCamera.isValid());
293 ocean_assert(world_T_camera.isValid());
294 ocean_assert(objectPoints.size() >= 3);
295 ocean_assert(objectPoints.size() == imagePoints.size());
296
297 const HomogenousMatrix4 flippedCamera_T_world(PinholeCamera::standard2InvertedFlipped(world_T_camera));
298
299 HomogenousMatrix4 optimizedInvertedFlippedPose;
300 if (!optimizePoseIF(pinholeCamera, flippedCamera_T_world, objectPoints, imagePoints, distortImagePoints, optimizedInvertedFlippedPose, iterations, estimator, lambda, lambdaFactor, initialError, finalError))
301 {
302 return false;
303 }
304
305 world_T_optimizedCamera = PinholeCamera::invertedFlipped2Standard(optimizedInvertedFlippedPose);
306 return true;
307}
308
309inline 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)
310{
311 ocean_assert(anyCamera.isValid());
312 ocean_assert(world_T_camera.isValid());
313 ocean_assert(objectPoints.size() >= 3);
314 ocean_assert(objectPoints.size() == imagePoints.size());
315
316 const HomogenousMatrix4 flippedCamera_T_world(Camera::standard2InvertedFlipped(world_T_camera));
317
318 HomogenousMatrix4 optimizedFlippedCamera_T_world;
319 if (!optimizePoseIF(anyCamera, flippedCamera_T_world, objectPoints, imagePoints, optimizedFlippedCamera_T_world, iterations, estimator, lambda, lambdaFactor, initialError, finalError, intermediateRobustErrors, gravityConstraints))
320 {
321 return false;
322 }
323
324 world_T_optimizedCamera = Camera::invertedFlipped2Standard(optimizedFlippedCamera_T_world);
325 return true;
326}
327
328inline 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)
329{
330 ocean_assert(camera.isValid());
331 ocean_assert(world_T_camera.isValid());
332
333 ocean_assert(objectPoints.size() >= 3u);
334 ocean_assert(objectPoints.size() == imagePoints.size());
335
336 const HomogenousMatrix4 flippedCamera_T_world(PinholeCamera::standard2InvertedFlipped(world_T_camera));
337
338 HomogenousMatrix4 optimizedFlippedCamera_T_world(false);
339 if (!optimizePoseIF(camera, flippedCamera_T_world, objectPoints, imagePoints, optimizedFlippedCamera_T_world, iterations, estimator, lambda, lambdaFactor, initialError, finalError, intermediateRobustErrors, invertedCovariances, gravityConstraints))
340 {
341 return false;
342 }
343
344 world_T_optimizedCamera = PinholeCamera::invertedFlipped2Standard(optimizedFlippedCamera_T_world);
345 return true;
346}
347
348inline 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)
349{
350 const AnyCameraPinhole anyCamera(PinholeCamera(pinholeCamera, distortImagePoints));
351
352 constexpr Scalars* intermediateRobustErrors = nullptr;
353 constexpr const GravityConstraints* gravityConstraints = nullptr;
354
355 return optimizePose(anyCamera, world_T_camera, objectPoints, imagePoints, world_T_optimizedCamera, iterations, estimator, lambda, lambdaFactor, initialError, finalError, intermediateRobustErrors, invertedCovariances, gravityConstraints);
356}
357
358inline 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)
359{
360 ocean_assert(world_T_camera.isValid() && zoom > Numeric::eps());
361 ocean_assert(objectPoints.size() >= 3u);
362 ocean_assert(objectPoints.size() == imagePoints.size());
363
364 const HomogenousMatrix4 flippedCamera_T_world(PinholeCamera::standard2InvertedFlipped(world_T_camera));
365
366 HomogenousMatrix4 optimizedInvertedFlippedPose;
367 if (!optimizePoseZoomIF(pinholeCamera, flippedCamera_T_world, zoom, objectPoints, imagePoints, distortImagePoints, optimizedInvertedFlippedPose, optimizedZoom, iterations, estimator, lambda, lambdaFactor, initialError, finalError, invertedCovariances))
368 {
369 return false;
370 }
371
372 world_T_optimizedCamera = PinholeCamera::invertedFlipped2Standard(optimizedInvertedFlippedPose);
373 return true;
374}
375
376}
377
378}
379
380#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:130
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:608
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:734
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:757
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 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=20u, const Estimator::EstimatorType estimator=Estimator::ET_SQUARE, Scalar lambda=Scalar(0.001), const Scalar lambdaFactor=10, Scalar *initialError=nullptr, Scalar *finalError=nullptr)
Deprecated.
Definition NonLinearOptimizationPose.h:290
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=20u, const Estimator::EstimatorType estimator=Estimator::ET_SQUARE, Scalar lambda=Scalar(0.001), const Scalar lambdaFactor=10, Scalar *initialError=nullptr, Scalar *finalError=nullptr)
Deprecated.
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:358
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 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.
bool isValid() const
Returns whether this camera is valid.
Definition PinholeCamera.h:1762
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