Ocean
Loading...
Searching...
No Matches
NonLinearOptimizationCamera.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_CAMERA_H
9#define META_OCEAN_GEOMETRY_NON_LINEAR_OPTIMIZATION_CAMERA_H
10
13
18
19namespace Ocean
20{
21
22namespace Geometry
23{
24
25/**
26 * This class implements least square or robust optimization algorithms for camera profiles.
27 * @ingroup geometry
28 */
29class OCEAN_GEOMETRY_EXPORT NonLinearOptimizationCamera : protected NonLinearOptimization
30{
31 public:
32
33 /**
34 * Definition of individual optimization strategies for how the camera parameters can be optimized.
35 */
36 enum OptimizationStrategy : uint32_t
37 {
38 /// An invalid optimization strategy.
39 OS_INVALID = 0u,
40 /// One stage optimization: Only the focal length parameter(s) of the camera profile will be optimized (at once).
42 /// Two stage optimization: First the focal length parameter(s) will be optimized in a first stage, followed by the principal point.
44 /// Multi-stage optimization: First the focal length parameter(s) will be optimized in a first stage, followed by the principal point, followed by the major distortion parameters (one after another).
46 /// Single stage optimization: All parameters of the camera profile will be optimized at once.
48 /// Multi-stage optimization: First the focal length parameter(s) will be optimized in a first stage, followed by the principal point, followed by all distortion parameters (one after another), this strategy will create the most accurate camera profile.
50 };
51
52 protected:
53
54 /**
55 * Forward declaration of a base data class necessary to optimize rotational camera motion.
56 */
57 class CameraOrientationsBaseData;
58
59 /**
60 * Forward declaration of a base class allowing to optimized the camera profile.
61 * @tparam tParameters The number of parameters to optimized
62 */
63 template <unsigned int tParameters>
65
66 /**
67 * Forward declaration of the data class allowing to find an initial camera field of view for rotational camera motion.
68 */
69 class CameraOrientationsFovData;
70
71 /**
72 * Forward declaration of an optimization provider allowing to optimize the individual parameters of a camera profile.
73 * @tparam tOptimizationStrategy The optimization strategy to be used
74 */
75 template <PinholeCamera::OptimizationStrategy tOptimizationStrategy>
77
78 /**
79 * Forward declaration of the data class allowing to optimized the camera parameters for rotational camera motion.
80 * @tparam tParameters The number of parameters to optimized
81 */
82 template <unsigned int tParameters>
84
85 /**
86 * Forward declaration of an optimization provider allowing to optimize a camera profile and camera poses concurrently.
87 */
88 class CameraPosesOptimizationProvider;
89
90 /**
91 * Forward declaration of the data class allowing to optimized the camera parameters for unconstrained (translational and rotational) camera motion.
92 * @tparam tParameters The number of parameters to optimized
93 */
94 template <unsigned int tParameters>
96
97 public:
98
99 /**
100 * Determines the initial field of view for a set of camera frames with known orientations and groups of correspondences of ids of 3D object points and 2D image point locations from the individual frames.
101 * The number of correspondences may vary between the individual frames (groups).<br>
102 * Each group may address individual object points, however the larger the intersection of sets between the individual 3D object points in the individual frames the better the optimization result.
103 * @param pinholeCamera The pinhole camera profile for which the better field of view will be determined, must be valid
104 * @param world_R_cameras The accessor for the known orientations of the individual camera frames
105 * @param correspondenceGroups The accessor for the individual groups of point correspondences, one group for each orientation
106 * @param optimizedCamera The resulting camera profile with best matching field of view
107 * @param world_R_optimizedOrientations Optional accessor for the optimized camera orientations matching with the new camera profile
108 * @param lowerFovX The lower bound of the possible horizontal field of view in radian, with range (0, upperFovX]
109 * @param upperFovX The upper bound of the possible horizontal field of view in radian, with range [lowerFovX, PI)
110 * @param steps The number of steps in which the defined angle range is subdivided, with range [4, infinity)
111 * @param recursiveIterations The number of recursive iterations that will be applied to improve the accuracy, start with the second iteration the search for the best fov is centered at the position of the previous iteration, with range [1, infinity)
112 * @param onlyFrontObjectPoints True, to avoid that the optimized 3D position lies behind any camera
113 * @param significantResult Optional resulting whether the resulting field of view has an significant impact on the error; True, of so
114 * @param finalError Optional resulting averaged square pixel error for the camera profile with the best matching field of view
115 * @param worker Optional worker object to distribute the computation
116 * @param abort Optional abort statement allowing to stop the execution; True, if the execution has to stop
117 * @return True, if succeeded and the execution has not been aborted
118 */
119 static bool findInitialFieldOfView(const PinholeCamera& pinholeCamera, const ConstIndexedAccessor<SquareMatrix3>& world_R_cameras, const PoseGroupsAccessor& correspondenceGroups, PinholeCamera& optimizedCamera, NonconstIndexedAccessor<SquareMatrix3>* world_R_optimizedOrientations, const Scalar lowerFovX = Numeric::deg2rad(40), const Scalar upperFovX = Numeric::deg2rad(90), const unsigned int steps = 10u, const unsigned int recursiveIterations = 3u, const bool onlyFrontObjectPoints = true, bool* significantResult = nullptr, Scalar* finalError = nullptr, Worker* worker = nullptr, bool* abort = nullptr);
120
121 /**
122 * Determines the initial field of view for a set of camera frames with known poses and groups of correspondences between pose indices and 2D image points locations within the pose frames while also the provided object points are optimized.
123 * The number of correspondences may vary between the individual frames (groups).<br>
124 * Each group may address individual object points, however the larger the intersection of sets between the individual 3D object points in the individual frames the better the optimization result.
125 * @param pinholeCamera The pinhole camera profile for which the better field of view will be determined, must be valid
126 * @param world_T_cameras The accessor for the known poses of the individual camera frames
127 * @param objectPoints The accessor for the individual 3D object points
128 * @param correspondenceGroups The accessor for the individual groups of correspondences between pose ids and image point location, one group for each object point
129 * @param optimizedCamera The resulting camera profile with best matching field of view
130 * @param world_T_optimizedCameras Optional accessor for the resulting optimized camera poses matching with the new camera profile
131 * @param optimizedObjectPoints Optional accessor for the resulting optimized object point locations
132 * @param lowerFovX The lower bound of the possible horizontal field of view in radian, with range (0, upperFovX]
133 * @param upperFovX The upper bound of the possible horizontal field of view in radian, with range [lowerFovX, PI)
134 * @param steps The number of steps in which the defined angle range is subdivided, with range [4, infinity)
135 * @param recursiveIterations The number of recursive iterations that will be applied to improve the accuracy, start with the second iteration the search for the best fov is centered at the position of the previous iteration, with range [1, infinity)
136 * @param onlyFrontObjectPoints True, to avoid that the optimized 3D position lies behind any camera
137 * @param significantResult Optional resulting whether the resulting field of view has an significant impact on the error; True, of so
138 * @param finalError Optional resulting averaged square pixel error for the camera profile with the best matching field of view
139 * @param worker Optional worker object to distribute the computation
140 * @param abort Optional abort statement allowing to stop the execution; True, if the execution has to stop
141 * @return True, if succeeded and the execution has not been aborted
142 */
143 static bool findInitialFieldOfView(const PinholeCamera& pinholeCamera, const ConstIndexedAccessor<HomogenousMatrix4>& world_T_cameras, const ConstIndexedAccessor<Vector3>& objectPoints, const ObjectPointGroupsAccessor& correspondenceGroups, PinholeCamera& optimizedCamera, NonconstIndexedAccessor<HomogenousMatrix4>* world_T_optimizedCameras, NonconstIndexedAccessor<Vector3>* optimizedObjectPoints, const Scalar lowerFovX = Numeric::deg2rad(40), const Scalar upperFovX = Numeric::deg2rad(90), const unsigned int steps = 10u, const unsigned int recursiveIterations = 3u, const bool onlyFrontObjectPoints = true, bool* significantResult = nullptr, Scalar* finalError = nullptr, Worker* worker = nullptr, bool* abort = nullptr);
144
145 /**
146 * Optimizes the individual parameters of a camera profile by minimizing the pixel error between normalized image points (projected 3D object points) and their corresponding 2D image point observations.
147 * Which parameter of the camera profile will be optimized depends on the specified optimization strategy.
148 * @param pinholeCamera The pinhole camera profile with initial distortion parameters to optimize
149 * @param normalizedObjectPoints The accessor for the projected 3D object points (the normalized image/object points)
150 * @param imagePoints imagePoints The accessor for the observations of the projected 3D object points, defined in the pixel coordinate system, each point corresponds to one normalized object point
151 * @param optimizationStrategy The optimization strategy to be used
152 * @param optimizedCamera Resulting optimized camera object holding optimized intrinsic and distortion parameters
153 * @param iterations Number of iterations to be applied at most, if no convergence can be reached
154 * @param estimator Robust error estimator to be used
155 * @param lambda Initial Levenberg-Marquardt damping value which may be changed after each iteration using the damping factor, with range [0, infinity)
156 * @param lambdaFactor Levenberg-Marquardt damping factor to be applied to the damping value, with range [1, infinity)
157 * @param initialError Optional resulting averaged pixel error for the given initial parameters, in relation to the defined estimator
158 * @param finalError Optional resulting averaged pixel error for the final optimized parameters, in relation to the defined estimator
159 * @return True, if succeeded
160 */
161 static bool optimizeCamera(const PinholeCamera& pinholeCamera, const ConstIndexedAccessor<Vector2>& normalizedObjectPoints, const ConstIndexedAccessor<Vector2>& imagePoints, const PinholeCamera::OptimizationStrategy optimizationStrategy, PinholeCamera& optimizedCamera, const unsigned int iterations = 20u, const Estimator::EstimatorType estimator = Estimator::ET_SQUARE, Scalar lambda = Scalar(0.001), const Scalar lambdaFactor = Scalar(5), Scalar* initialError = nullptr, Scalar* finalError = nullptr);
162
163 /**
164 * Optimizes the camera parameters of a given camera profile for a set of camera frames with known orientation and groups of 2D/3D point correspondences from individual frames.
165 * The number of points correspondences may vary between the individual frames (groups).<br>
166 * Each group may address individual object points.
167 * @param pinholeCamera The pinhole camera profile to optimized
168 * @param world_R_cameras The accessor for the known orientations of the individual camera frames
169 * @param correspondenceGroups The accessor for the individual groups of point correspondences, one group for each orientation
170 * @param optimizationStrategy The optimization strategy
171 * @param optimizedCamera The resulting camera profile with ideal field of view
172 * @param world_R_optimizedCameras Optional accessor for the optimized camera orientations matching with the new camera profile
173 * @param iterations Number of iterations to be applied at most, if no convergence can be reached
174 * @param estimator Robust error estimator to be used
175 * @param lambda Initial Levenberg-Marquardt damping value which may be changed after each iteration using the damping factor, with range [0, infinity)
176 * @param lambdaFactor Levenberg-Marquardt damping factor to be applied to the damping value, with range [1, infinity)
177 * @param onlyFrontObjectPoints True, to avoid that the optimized 3D position lies behind any camera
178 * @param initialError Optional resulting averaged pixel error for the given initial parameters, in relation to the defined estimator
179 * @param finalError Optional resulting averaged pixel error for the final optimized parameters, in relation to the defined estimator
180 * @param intermediateErrors Optional resulting intermediate averaged pixel errors for the individual optimization steps, in relation to the defined estimator
181 * @return True, if succeeded
182 */
183 static bool optimizeCameraOrientations(const PinholeCamera& pinholeCamera, const ConstIndexedAccessor<SquareMatrix3>& world_R_cameras, const PoseGroupsAccessor& correspondenceGroups, const PinholeCamera::OptimizationStrategy optimizationStrategy, PinholeCamera& optimizedCamera, NonconstIndexedAccessor<SquareMatrix3>* world_R_optimizedCameras, const unsigned int iterations, const Geometry::Estimator::EstimatorType estimator = Geometry::Estimator::ET_SQUARE, const Scalar lambda = Scalar(0.001), const Scalar lambdaFactor = Scalar(5), const bool onlyFrontObjectPoints = true, Scalar* initialError = nullptr, Scalar* finalError = nullptr, Scalars* intermediateErrors = nullptr);
184
185 /**
186 * Minimizes the projection error between the projections of static 3D object points and their corresponding image points in several 6DOF camera poses.
187 * The camera profile as well as the camera poses are optimized concurrently.
188 * @param camera The camera profile to optimize, must be valid
189 * @param world_T_cameras The individual camera poses, one pose for each pair of groups of object points and image points
190 * @param objectPointGroups The accessor for the individual groups of 3D object points, one group for each camera pose with at least one object point
191 * @param imagePointGroups The accessor for the individual groups of 2D image points, one group for each camera pose and one image point for each corresponding object point
192 * @param optimizedCamera The resulting optimized camera profile
193 * @param world_T_optimizedCameras Optional accessor for the resulting optimized camera poses, matching with the new camera profile
194 * @param iterations The maximal number of iterations to be applied per optimization stage (depending on the optimizationStrategy), if no convergence can be reached
195 * @param optimizationStrategy The optimization strategy to be used
196 * @param estimator Robust error estimator to be used
197 * @param lambda Initial Levenberg-Marquardt damping value which may be changed after each iteration using the damping factor, with range [0, infinity)
198 * @param lambdaFactor Levenberg-Marquardt damping factor to be applied to the damping value, with range [1, infinity)
199 * @param onlyFrontObjectPoints True, to avoid that the optimized 3D position lies behind any camera
200 * @param distortionConstrainmentFactor Factor used to constrain higher-order distortion parameters based on the magnitude of lower-order ones during optimization, with range [0, infinity); 0 to disable constrainment
201 * @param initialError Optional resulting averaged pixel error for the given initial parameters, in relation to the defined estimator
202 * @param finalError Optional resulting averaged pixel error for the final optimized parameters, in relation to the defined estimator
203 * @param intermediateErrors Optional resulting intermediate averaged pixel errors for the individual optimization steps, in relation to the defined estimator
204 * @return True, if succeeded
205 * @see optimizeCameraPoseIF().
206 */
207 static bool optimizeCameraPoses(const AnyCamera& camera, const ConstIndexedAccessor<HomogenousMatrix4>& world_T_cameras, const ConstIndexedAccessor<Vectors3>& objectPointGroups, const ConstIndexedAccessor<Vectors2>& imagePointGroups, SharedAnyCamera& optimizedCamera, NonconstIndexedAccessor<HomogenousMatrix4>* world_T_optimizedCameras, const unsigned int iterations, const OptimizationStrategy optimizationStrategy = OS_ALL_PARAMETERS_AFTER_ANOTHER, const Estimator::EstimatorType estimator = Estimator::ET_SQUARE, Scalar lambda = Scalar(0.001), const Scalar lambdaFactor = Scalar(5), const bool onlyFrontObjectPoints = true, const Scalar distortionConstrainmentFactor = Scalar(0), Scalar* initialError = nullptr, Scalar* finalError = nullptr, Scalars* intermediateErrors = nullptr);
208
209 /**
210 * Minimizes the projection error between the projections of static 3D object points and their corresponding image points in several 6DOF camera poses.
211 * The given poses must be inverted and flipped around the new x axis by 180 degree.<br>
212 * All parameters are identical to optimizeCameraPoses(), with the exception that the poses are flipped.
213 * @param distortionConstrainmentFactor Factor used to constrain higher-order distortion parameters based on the magnitude of lower-order ones during optimization, with range [0, infinity); 0 to disable constrainment
214 * @see optimizeCameraPoses().
215 */
216 static bool optimizeCameraPosesIF(const AnyCamera& camera, const ConstIndexedAccessor<HomogenousMatrix4>& flippedCameras_T_world, const ConstIndexedAccessor<Vectors3>& objectPointGroups, const ConstIndexedAccessor<Vectors2>& imagePointGroups, SharedAnyCamera& optimizedCamera, NonconstIndexedAccessor<HomogenousMatrix4>* flippedOptimizedCameras_T_world, const unsigned int iterations, const OptimizationStrategy optimizationStrategy = OS_ALL_PARAMETERS_AFTER_ANOTHER, const Estimator::EstimatorType estimator = Estimator::ET_SQUARE, Scalar lambda = Scalar(0.001), const Scalar lambdaFactor = Scalar(5), const bool onlyFrontObjectPoints = true, const Scalar distortionConstrainmentFactor = Scalar(0), Scalar* initialError = nullptr, Scalar* finalError = nullptr, Scalars* intermediateErrors = nullptr);
217
218 /**
219 * Deprecated.
220 *
221 * Minimizes the projection error between the projections of static 3D object points and their corresponding image points in several 6DOF camera poses.
222 * The camera profile as well as the camera poses are optimized concurrently.
223 * @param pinholeCamera The pinhole camera holding intrinsic and distortion parameters to minimize the projection error for.
224 * @param world_T_cameras The individual camera poses, one pose for each pair of groups of object points and image points
225 * @param objectPointGroups The accessor for the individual groups of 3D object points, one group for each camera pose with at least one object point
226 * @param imagePointGroups The accessor for the individual groups of 2D image points, one group for each camera pose and one image point for each corresponding object point
227 * @param optimizedCamera The resulting optimized camera profile
228 * @param world_T_optimizedCameras Optional accessor for the resulting optimized camera poses, matching with the new camera profile
229 * @param iterations Number of iterations to be applied at most, if no convergence can be reached
230 * @param estimator Robust error estimator to be used
231 * @param lambda Initial Levenberg-Marquardt damping value which may be changed after each iteration using the damping factor, with range [0, infinity)
232 * @param lambdaFactor Levenberg-Marquardt damping factor to be applied to the damping value, with range [1, infinity)
233 * @param onlyFrontObjectPoints True, to avoid that the optimized 3D position lies behind any camera
234 * @param initialError Optional resulting averaged pixel error for the given initial parameters, in relation to the defined estimator
235 * @param finalError Optional resulting averaged pixel error for the final optimized parameters, in relation to the defined estimator
236 * @param intermediateErrors Optional resulting intermediate averaged pixel errors for the individual optimization steps, in relation to the defined estimator
237 * @return True, if succeeded
238 * @see optimizeCameraPoseIF().
239 */
240 static bool optimizeCameraPoses(const PinholeCamera& pinholeCamera, const ConstIndexedAccessor<HomogenousMatrix4>& world_T_cameras, const ConstIndexedAccessor<Vectors3>& objectPointGroups, const ConstIndexedAccessor<Vectors2>& imagePointGroups, PinholeCamera& optimizedCamera, NonconstIndexedAccessor<HomogenousMatrix4>* world_T_optimizedCameras, const unsigned int iterations, const Estimator::EstimatorType estimator = Estimator::ET_SQUARE, Scalar lambda = Scalar(0.001), const Scalar lambdaFactor = Scalar(5), const bool onlyFrontObjectPoints = true, Scalar* initialError = nullptr, Scalar* finalError = nullptr, Scalars* intermediateErrors = nullptr);
241
242 /**
243 * Deprecated.
244 *
245 * Minimizes the projection error between the projections of static 3D object points and their corresponding image points in several 6DOF camera poses.
246 * The given poses must be inverted and flipped around the new x axis by 180 degree.<br>
247 * @see optimizeCameraPose().
248 */
249 static bool optimizeCameraPosesIF(const PinholeCamera& pinholeCamera, const ConstIndexedAccessor<HomogenousMatrix4>& flippedCameras_T_world, const ConstIndexedAccessor<Vectors3>& objectPointGroups, const ConstIndexedAccessor<Vectors2>& imagePointGroups, PinholeCamera& optimizedCamera, NonconstIndexedAccessor<HomogenousMatrix4>* flippedOptimizedCameras_T_world, const unsigned int iterations, const Estimator::EstimatorType estimator = Estimator::ET_SQUARE, Scalar lambda = Scalar(0.001), const Scalar lambdaFactor = Scalar(5), const bool onlyFrontObjectPoints = true, Scalar* initialError = nullptr, Scalar* finalError = nullptr, Scalars* intermediateErrors = nullptr);
250
251 /**
252 * Optimizes the camera parameters of a given camera profile for a set of given camera poses and a set of given 3D object points by minimizing the projection error between the 3D object points and the corresponding 2D image points.
253 * This function also optimized the camera poses and the locations of the 3D object point while the camera profile is optimized.<br>
254 * The number of 2D/3D point correspondences may vary between the individual frames (groups).<br>
255 * Each group may address individual object points, however the larger the intersection of sets between the individual 3D object points in the individual frames the better the optimization result.
256 * @param pinholeCamera The pinhole camera profile to optimized
257 * @param world_T_cameras The accessor for the known poses of the individual camera frames
258 * @param objectPoints The accessor for the known 3D object points locations
259 * @param correspondenceGroups The accessor for the individual groups of correspondences between pose indices and image points, one group for each object point
260 * @param optimizationStrategy The optimization strategy for the camera profile
261 * @param optimizedCamera The resulting optimized camera profile
262 * @param world_T_optimizedCameras Optional accessor for the resulting optimized camera poses, matching with the new camera profile
263 * @param optimizedObjectPoints Optional accessor for the resulting optimized 3D object point locations, matching with the new camera profile
264 * @param iterations Number of iterations to be applied at most, if no convergence can be reached
265 * @param estimator Robust error estimator to be used
266 * @param lambda Initial Levenberg-Marquardt damping value which may be changed after each iteration using the damping factor, with range [0, infinity)
267 * @param lambdaFactor Levenberg-Marquardt damping factor to be applied to the damping value, with range [1, infinity)
268 * @param onlyFrontObjectPoints True, to avoid that the optimized 3D position lies behind any camera
269 * @param initialError Optional resulting averaged pixel error for the given initial parameters, in relation to the defined estimator
270 * @param finalError Optional resulting averaged pixel error for the final optimized parameters, in relation to the defined estimator
271 * @param intermediateErrors Optional resulting intermediate averaged pixel errors for the individual optimization steps, in relation to the defined estimator
272 * @return True, if succeeded
273 */
274 static bool optimizeCameraObjectPointsPoses(const PinholeCamera& pinholeCamera, const ConstIndexedAccessor<HomogenousMatrix4>& world_T_cameras, const ConstIndexedAccessor<Vector3>& objectPoints, const ObjectPointGroupsAccessor& correspondenceGroups, const PinholeCamera::OptimizationStrategy optimizationStrategy, PinholeCamera& optimizedCamera, NonconstIndexedAccessor<HomogenousMatrix4>* world_T_optimizedCameras, NonconstIndexedAccessor<Vector3>* optimizedObjectPoints, const unsigned int iterations, const Geometry::Estimator::EstimatorType estimator = Geometry::Estimator::ET_SQUARE, const Scalar lambda = Scalar(0.001), const Scalar lambdaFactor = Scalar(5), const bool onlyFrontObjectPoints = true, Scalar* initialError = nullptr, Scalar* finalError = nullptr, Scalars* intermediateErrors = nullptr);
275
276 /**
277 * Returns the number of camera parameters which should be optimized during individual optimization stages.
278 * @param camera The camera profile for which the number of parameters will be returned, must be valid
279 * @param optimizationStrategy The optimization strategy for which the number of parameter will be returned, one for each optimization stage
280 * @return The number of parameters for each optimization stage
281 */
282 static std::vector<size_t> cameraParametersPerOptimizationStage(const AnyCamera& camera, const OptimizationStrategy optimizationStrategy);
283
284 protected:
285
286 /**
287 * Determines the initial field of view for a set of camera frames with known orientations and groups of correspondences of ids of 3D object points and 2D image point locations from the individual frames.
288 * The number of correspondences may vary between the individual frames (groups).<br>
289 * Each group may address individual object points, however the larger the intersection of sets between the individual 3D object points in the individual frames the better the optimization result.
290 * @param pinholeCamera The pinhole camera profile for which the better field of view will be determined, must be valid
291 * @param orientations The accessor for the known orientations of the individual camera frames
292 * @param correspondenceGroups The accessor for the individual groups of point correspondences, one group for each orientation
293 * @param optimizedCamera The resulting camera profile with best matching field of view
294 * @param optimizedOrientations Optional accessor for the optimized camera orientations matching with the new camera profile
295 * @param lowerFovX The lower bound of the possible horizontal field of view in radian, with range (0, upperFovX]
296 * @param upperFovX The upper bound of the possible horizontal field of view in radian, with range [lowerFovX, PI)
297 * @param overallSteps The overall number of steps in which the defined angle range is subdivided, with range [4, infinity)
298 * @param onlyFrontObjectPoints True, to avoid that the optimized 3D position lies behind any camera
299 * @param bestError Resulting averaged square pixel error for the camera profile with the best matching field of view
300 * @param allErrors Optional vector of all errors that have been determined (can be used to decide whether a resulting best camera profile is significantly different from all other camera profiles)
301 * @param lock Lock object, must be defined if this function is executed in parallel on individual threads, nullptr otherwise
302 * @param abort Optional abort statement allowing to stop the execution; True, if the execution has to stop
303 * @param firstStep The first step to be handled, with range [0, overallSteps)
304 * @param steps The number of steps which will be handled (from the entire number of overall steps), with range [1, overallSteps]
305 */
306 static void findInitialFieldOfViewSubset(const PinholeCamera* pinholeCamera, const ConstIndexedAccessor<SquareMatrix3>* orientations, const PoseGroupsAccessor* correspondenceGroups, PinholeCamera* optimizedCamera, SquareMatrices3* optimizedOrientations, const Scalar lowerFovX, const Scalar upperFovX, const unsigned int overallSteps, const bool onlyFrontObjectPoints, Scalar* bestError, Scalars* allErrors, Lock* lock, bool* abort, const unsigned int firstStep, const unsigned int steps);
307
308 /**
309 * Determines the initial field of view for a set of camera frames with known poses and groups of correspondences between pose indices and 2D image points locations within the pose frames.
310 * The number of correspondences may vary between the individual frames (groups).<br>
311 * Each group may address individual object points, however the larger the intersection of sets between the individual 3D object points in the individual frames the better the optimization result.
312 * @param pinholeCamera The pinhole camera profile for which the better field of view will be determined, must be valid
313 * @param poses The accessor for the known poses of the individual camera frames
314 * @param objectPoints The accessor for the individual 3D object points
315 * @param correspondenceGroups The accessor for the individual groups of correspondences between pose ids and image point location, one group for each object point
316 * @param optimizedCamera The resulting camera profile with best matching field of view
317 * @param optimizedPoses Optional accessor for the resulting optimized camera poses matching with the new camera profile
318 * @param optimizedObjectPoints Optional accessor for the resulting optimized object point locations
319 * @param lowerFovX The lower bound of the possible horizontal field of view in radian, with range (0, upperFovX]
320 * @param upperFovX The upper bound of the possible horizontal field of view in radian, with range [lowerFovX, PI)
321 * @param overallSteps The overall number of steps in which the defined angle range is subdivided, with range [4, infinity)
322 * @param onlyFrontObjectPoints True, to avoid that the optimized 3D position lies behind any camera
323 * @param bestError Resulting averaged square pixel error for the camera profile with the best matching field of view
324 * @param allErrors Optional vector of all errors that have been determined (can be used to decide whether a resulting best camera profile is significantly different from all other camera profiles)
325 * @param lock The lock object, must be defined if this function is executed in parallel on individual threads, nullptr otherwise
326 * @param abort Optional abort statement allowing to stop the execution; True, if the execution has to stop
327 * @param firstStep The first step to be handled, with range [0, overallSteps)
328 * @param steps The number of steps which will be handled (from the entire number of overall steps), with range [1, overallSteps]
329 */
330 static void findInitialFieldOfViewSubset(const PinholeCamera* pinholeCamera, const ConstIndexedAccessor<HomogenousMatrix4>* poses, const ConstIndexedAccessor<Vector3>* objectPoints, const ObjectPointGroupsAccessor* correspondenceGroups, PinholeCamera* optimizedCamera, HomogenousMatrices4* optimizedPoses, Vectors3* optimizedObjectPoints, const Scalar lowerFovX, const Scalar upperFovX, const unsigned int overallSteps, const bool onlyFrontObjectPoints, Scalar* bestError, Scalars* allErrors, Lock* lock, bool* abort, const unsigned int firstStep, const unsigned int steps);
331};
332
333}
334
335}
336
337#endif // META_OCEAN_GEOMETRY_NON_LINEAR_OPTIMIZATION_CAMERA_H
This class implements the abstract base class for all AnyCamera objects.
Definition AnyCamera.h:131
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 an abstract specialization of the accessor for groups of pairs for object point...
Definition NonLinearOptimization.h:158
This class implements an abstract specialization of the accessor for groups of pairs for poses.
Definition NonLinearOptimization.h:184
Forward declaration of the data class allowing to optimized the camera parameters for unconstrained (...
Definition NonLinearOptimizationCamera.h:95
Forward declaration of the data class allowing to optimized the camera parameters for rotational came...
Definition NonLinearOptimizationCamera.h:83
Forward declaration of a base class allowing to optimized the camera profile.
Definition NonLinearOptimizationCamera.h:64
Forward declaration of an optimization provider allowing to optimize the individual parameters of a c...
Definition NonLinearOptimizationCamera.h:76
This class implements least square or robust optimization algorithms for camera profiles.
Definition NonLinearOptimizationCamera.h:30
static bool findInitialFieldOfView(const PinholeCamera &pinholeCamera, const ConstIndexedAccessor< HomogenousMatrix4 > &world_T_cameras, const ConstIndexedAccessor< Vector3 > &objectPoints, const ObjectPointGroupsAccessor &correspondenceGroups, PinholeCamera &optimizedCamera, NonconstIndexedAccessor< HomogenousMatrix4 > *world_T_optimizedCameras, NonconstIndexedAccessor< Vector3 > *optimizedObjectPoints, const Scalar lowerFovX=Numeric::deg2rad(40), const Scalar upperFovX=Numeric::deg2rad(90), const unsigned int steps=10u, const unsigned int recursiveIterations=3u, const bool onlyFrontObjectPoints=true, bool *significantResult=nullptr, Scalar *finalError=nullptr, Worker *worker=nullptr, bool *abort=nullptr)
Determines the initial field of view for a set of camera frames with known poses and groups of corres...
static bool optimizeCameraObjectPointsPoses(const PinholeCamera &pinholeCamera, const ConstIndexedAccessor< HomogenousMatrix4 > &world_T_cameras, const ConstIndexedAccessor< Vector3 > &objectPoints, const ObjectPointGroupsAccessor &correspondenceGroups, const PinholeCamera::OptimizationStrategy optimizationStrategy, PinholeCamera &optimizedCamera, NonconstIndexedAccessor< HomogenousMatrix4 > *world_T_optimizedCameras, NonconstIndexedAccessor< Vector3 > *optimizedObjectPoints, const unsigned int iterations, const Geometry::Estimator::EstimatorType estimator=Geometry::Estimator::ET_SQUARE, const Scalar lambda=Scalar(0.001), const Scalar lambdaFactor=Scalar(5), const bool onlyFrontObjectPoints=true, Scalar *initialError=nullptr, Scalar *finalError=nullptr, Scalars *intermediateErrors=nullptr)
Optimizes the camera parameters of a given camera profile for a set of given camera poses and a set o...
static bool optimizeCameraOrientations(const PinholeCamera &pinholeCamera, const ConstIndexedAccessor< SquareMatrix3 > &world_R_cameras, const PoseGroupsAccessor &correspondenceGroups, const PinholeCamera::OptimizationStrategy optimizationStrategy, PinholeCamera &optimizedCamera, NonconstIndexedAccessor< SquareMatrix3 > *world_R_optimizedCameras, const unsigned int iterations, const Geometry::Estimator::EstimatorType estimator=Geometry::Estimator::ET_SQUARE, const Scalar lambda=Scalar(0.001), const Scalar lambdaFactor=Scalar(5), const bool onlyFrontObjectPoints=true, Scalar *initialError=nullptr, Scalar *finalError=nullptr, Scalars *intermediateErrors=nullptr)
Optimizes the camera parameters of a given camera profile for a set of camera frames with known orien...
static std::vector< size_t > cameraParametersPerOptimizationStage(const AnyCamera &camera, const OptimizationStrategy optimizationStrategy)
Returns the number of camera parameters which should be optimized during individual optimization stag...
static bool optimizeCamera(const PinholeCamera &pinholeCamera, const ConstIndexedAccessor< Vector2 > &normalizedObjectPoints, const ConstIndexedAccessor< Vector2 > &imagePoints, const PinholeCamera::OptimizationStrategy optimizationStrategy, PinholeCamera &optimizedCamera, const unsigned int iterations=20u, const Estimator::EstimatorType estimator=Estimator::ET_SQUARE, Scalar lambda=Scalar(0.001), const Scalar lambdaFactor=Scalar(5), Scalar *initialError=nullptr, Scalar *finalError=nullptr)
Optimizes the individual parameters of a camera profile by minimizing the pixel error between normali...
static bool optimizeCameraPoses(const AnyCamera &camera, const ConstIndexedAccessor< HomogenousMatrix4 > &world_T_cameras, const ConstIndexedAccessor< Vectors3 > &objectPointGroups, const ConstIndexedAccessor< Vectors2 > &imagePointGroups, SharedAnyCamera &optimizedCamera, NonconstIndexedAccessor< HomogenousMatrix4 > *world_T_optimizedCameras, const unsigned int iterations, const OptimizationStrategy optimizationStrategy=OS_ALL_PARAMETERS_AFTER_ANOTHER, const Estimator::EstimatorType estimator=Estimator::ET_SQUARE, Scalar lambda=Scalar(0.001), const Scalar lambdaFactor=Scalar(5), const bool onlyFrontObjectPoints=true, const Scalar distortionConstrainmentFactor=Scalar(0), Scalar *initialError=nullptr, Scalar *finalError=nullptr, Scalars *intermediateErrors=nullptr)
Minimizes the projection error between the projections of static 3D object points and their correspon...
static void findInitialFieldOfViewSubset(const PinholeCamera *pinholeCamera, const ConstIndexedAccessor< HomogenousMatrix4 > *poses, const ConstIndexedAccessor< Vector3 > *objectPoints, const ObjectPointGroupsAccessor *correspondenceGroups, PinholeCamera *optimizedCamera, HomogenousMatrices4 *optimizedPoses, Vectors3 *optimizedObjectPoints, const Scalar lowerFovX, const Scalar upperFovX, const unsigned int overallSteps, const bool onlyFrontObjectPoints, Scalar *bestError, Scalars *allErrors, Lock *lock, bool *abort, const unsigned int firstStep, const unsigned int steps)
Determines the initial field of view for a set of camera frames with known poses and groups of corres...
static bool optimizeCameraPosesIF(const AnyCamera &camera, const ConstIndexedAccessor< HomogenousMatrix4 > &flippedCameras_T_world, const ConstIndexedAccessor< Vectors3 > &objectPointGroups, const ConstIndexedAccessor< Vectors2 > &imagePointGroups, SharedAnyCamera &optimizedCamera, NonconstIndexedAccessor< HomogenousMatrix4 > *flippedOptimizedCameras_T_world, const unsigned int iterations, const OptimizationStrategy optimizationStrategy=OS_ALL_PARAMETERS_AFTER_ANOTHER, const Estimator::EstimatorType estimator=Estimator::ET_SQUARE, Scalar lambda=Scalar(0.001), const Scalar lambdaFactor=Scalar(5), const bool onlyFrontObjectPoints=true, const Scalar distortionConstrainmentFactor=Scalar(0), Scalar *initialError=nullptr, Scalar *finalError=nullptr, Scalars *intermediateErrors=nullptr)
Minimizes the projection error between the projections of static 3D object points and their correspon...
static bool optimizeCameraPosesIF(const PinholeCamera &pinholeCamera, const ConstIndexedAccessor< HomogenousMatrix4 > &flippedCameras_T_world, const ConstIndexedAccessor< Vectors3 > &objectPointGroups, const ConstIndexedAccessor< Vectors2 > &imagePointGroups, PinholeCamera &optimizedCamera, NonconstIndexedAccessor< HomogenousMatrix4 > *flippedOptimizedCameras_T_world, const unsigned int iterations, const Estimator::EstimatorType estimator=Estimator::ET_SQUARE, Scalar lambda=Scalar(0.001), const Scalar lambdaFactor=Scalar(5), const bool onlyFrontObjectPoints=true, Scalar *initialError=nullptr, Scalar *finalError=nullptr, Scalars *intermediateErrors=nullptr)
Deprecated.
OptimizationStrategy
Definition of individual optimization strategies for how the camera parameters can be optimized.
Definition NonLinearOptimizationCamera.h:37
@ OS_ALL_PARAMETERS_AT_ONCE
Single stage optimization: All parameters of the camera profile will be optimized at once.
Definition NonLinearOptimizationCamera.h:47
@ OS_UP_TO_MAJOR_DISTORTION_AFTER_ANOTHER
Multi-stage optimization: First the focal length parameter(s) will be optimized in a first stage,...
Definition NonLinearOptimizationCamera.h:45
@ OS_ALL_PARAMETERS_AFTER_ANOTHER
Multi-stage optimization: First the focal length parameter(s) will be optimized in a first stage,...
Definition NonLinearOptimizationCamera.h:49
@ OS_ONLY_FOCAL_LENGTH
One stage optimization: Only the focal length parameter(s) of the camera profile will be optimized (a...
Definition NonLinearOptimizationCamera.h:41
@ OS_UP_TO_PRINCIPAL_POINT_AFTER_ANOTHER
Two stage optimization: First the focal length parameter(s) will be optimized in a first stage,...
Definition NonLinearOptimizationCamera.h:43
static bool optimizeCameraPoses(const PinholeCamera &pinholeCamera, const ConstIndexedAccessor< HomogenousMatrix4 > &world_T_cameras, const ConstIndexedAccessor< Vectors3 > &objectPointGroups, const ConstIndexedAccessor< Vectors2 > &imagePointGroups, PinholeCamera &optimizedCamera, NonconstIndexedAccessor< HomogenousMatrix4 > *world_T_optimizedCameras, const unsigned int iterations, const Estimator::EstimatorType estimator=Estimator::ET_SQUARE, Scalar lambda=Scalar(0.001), const Scalar lambdaFactor=Scalar(5), const bool onlyFrontObjectPoints=true, Scalar *initialError=nullptr, Scalar *finalError=nullptr, Scalars *intermediateErrors=nullptr)
Deprecated.
static void findInitialFieldOfViewSubset(const PinholeCamera *pinholeCamera, const ConstIndexedAccessor< SquareMatrix3 > *orientations, const PoseGroupsAccessor *correspondenceGroups, PinholeCamera *optimizedCamera, SquareMatrices3 *optimizedOrientations, const Scalar lowerFovX, const Scalar upperFovX, const unsigned int overallSteps, const bool onlyFrontObjectPoints, Scalar *bestError, Scalars *allErrors, Lock *lock, bool *abort, const unsigned int firstStep, const unsigned int steps)
Determines the initial field of view for a set of camera frames with known orientations and groups of...
static bool findInitialFieldOfView(const PinholeCamera &pinholeCamera, const ConstIndexedAccessor< SquareMatrix3 > &world_R_cameras, const PoseGroupsAccessor &correspondenceGroups, PinholeCamera &optimizedCamera, NonconstIndexedAccessor< SquareMatrix3 > *world_R_optimizedOrientations, const Scalar lowerFovX=Numeric::deg2rad(40), const Scalar upperFovX=Numeric::deg2rad(90), const unsigned int steps=10u, const unsigned int recursiveIterations=3u, const bool onlyFrontObjectPoints=true, bool *significantResult=nullptr, Scalar *finalError=nullptr, Worker *worker=nullptr, bool *abort=nullptr)
Determines the initial field of view for a set of camera frames with known orientations and groups of...
This class implements the basic functions for least square or robust optimization algorithms for non ...
Definition NonLinearOptimization.h:33
This class implements a recursive lock object.
Definition Lock.h:31
This class implements a base class for all indexed-based accessors allowing a non-constant reference ...
Definition Accessor.h:284
OptimizationStrategy
Definition of individual optimization strategies for camera parameters.
Definition PinholeCamera.h:178
This class implements a worker able to distribute function calls over different threads.
Definition Worker.h:33
float Scalar
Definition of a scalar type.
Definition Math.h:129
std::shared_ptr< AnyCamera > SharedAnyCamera
Definition of a shared pointer holding an AnyCamera object with Scalar precision.
Definition AnyCamera.h:61
std::vector< HomogenousMatrix4 > HomogenousMatrices4
Definition of a vector holding HomogenousMatrix4 objects.
Definition HomogenousMatrix4.h:73
std::vector< SquareMatrix3 > SquareMatrices3
Definition of a vector holding SquareMatrix3 objects.
Definition SquareMatrix3.h:72
std::vector< Vector3 > Vectors3
Definition of a vector holding Vector3 objects.
Definition Vector3.h:65
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