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 initialError Optional resulting averaged pixel error for the given initial parameters, in relation to the defined estimator
201 * @param finalError Optional resulting averaged pixel error for the final optimized parameters, in relation to the defined estimator
202 * @param intermediateErrors Optional resulting intermediate averaged pixel errors for the individual optimization steps, in relation to the defined estimator
203 * @return True, if succeeded
204 * @see optimizeCameraPoseIF().
205 */
206 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, Scalar* initialError = nullptr, Scalar* finalError = nullptr, Scalars* intermediateErrors = nullptr);
207
208 /**
209 * Minimizes the projection error between the projections of static 3D object points and their corresponding image points in several 6DOF camera poses.
210 * The given poses must be inverted and flipped around the new x axis by 180 degree.<br>
211 * @see optimizeCameraPose().
212 */
213 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, Scalar* initialError = nullptr, Scalar* finalError = nullptr, Scalars* intermediateErrors = nullptr);
214
215 /**
216 * Deprecated.
217 *
218 * Minimizes the projection error between the projections of static 3D object points and their corresponding image points in several 6DOF camera poses.
219 * The camera profile as well as the camera poses are optimized concurrently.
220 * @param pinholeCamera The pinhole camera holding intrinsic and distortion parameters to minimize the projection error for.
221 * @param world_T_cameras The individual camera poses, one pose for each pair of groups of object points and image points
222 * @param objectPointGroups The accessor for the individual groups of 3D object points, one group for each camera pose with at least one object point
223 * @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
224 * @param optimizedCamera The resulting optimized camera profile
225 * @param world_T_optimizedCameras Optional accessor for the resulting optimized camera poses, matching with the new camera profile
226 * @param iterations Number of iterations to be applied at most, if no convergence can be reached
227 * @param estimator Robust error estimator to be used
228 * @param lambda Initial Levenberg-Marquardt damping value which may be changed after each iteration using the damping factor, with range [0, infinity)
229 * @param lambdaFactor Levenberg-Marquardt damping factor to be applied to the damping value, with range [1, infinity)
230 * @param onlyFrontObjectPoints True, to avoid that the optimized 3D position lies behind any camera
231 * @param initialError Optional resulting averaged pixel error for the given initial parameters, in relation to the defined estimator
232 * @param finalError Optional resulting averaged pixel error for the final optimized parameters, in relation to the defined estimator
233 * @param intermediateErrors Optional resulting intermediate averaged pixel errors for the individual optimization steps, in relation to the defined estimator
234 * @return True, if succeeded
235 * @see optimizeCameraPoseIF().
236 */
237 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);
238
239 /**
240 * Deprecated.
241 *
242 * Minimizes the projection error between the projections of static 3D object points and their corresponding image points in several 6DOF camera poses.
243 * The given poses must be inverted and flipped around the new x axis by 180 degree.<br>
244 * @see optimizeCameraPose().
245 */
246 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);
247
248 /**
249 * 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.
250 * This function also optimized the camera poses and the locations of the 3D object point while the camera profile is optimized.<br>
251 * The number of 2D/3D point correspondences may vary between the individual frames (groups).<br>
252 * 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.
253 * @param pinholeCamera The pinhole camera profile to optimized
254 * @param world_T_cameras The accessor for the known poses of the individual camera frames
255 * @param objectPoints The accessor for the known 3D object points locations
256 * @param correspondenceGroups The accessor for the individual groups of correspondences between pose indices and image points, one group for each object point
257 * @param optimizationStrategy The optimization strategy for the camera profile
258 * @param optimizedCamera The resulting optimized camera profile
259 * @param world_T_optimizedCameras Optional accessor for the resulting optimized camera poses, matching with the new camera profile
260 * @param optimizedObjectPoints Optional accessor for the resulting optimized 3D object point locations, matching with the new camera profile
261 * @param iterations Number of iterations to be applied at most, if no convergence can be reached
262 * @param estimator Robust error estimator to be used
263 * @param lambda Initial Levenberg-Marquardt damping value which may be changed after each iteration using the damping factor, with range [0, infinity)
264 * @param lambdaFactor Levenberg-Marquardt damping factor to be applied to the damping value, with range [1, infinity)
265 * @param onlyFrontObjectPoints True, to avoid that the optimized 3D position lies behind any camera
266 * @param initialError Optional resulting averaged pixel error for the given initial parameters, in relation to the defined estimator
267 * @param finalError Optional resulting averaged pixel error for the final optimized parameters, in relation to the defined estimator
268 * @param intermediateErrors Optional resulting intermediate averaged pixel errors for the individual optimization steps, in relation to the defined estimator
269 * @return True, if succeeded
270 */
271 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);
272
273 /**
274 * Returns the number of camera parameters which should be optimized during individual optimization stages.
275 * @param camera The camera profile for which the number of parameters will be returned, must be valid
276 * @param optimizationStrategy The optimization strategy for which the number of parameter will be returned, one for each optimization stage
277 * @return The number of parameters for each optimization stage
278 */
279 static std::vector<size_t> cameraParametersPerOptimizationStage(const AnyCamera& camera, const OptimizationStrategy optimizationStrategy);
280
281 protected:
282
283 /**
284 * 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.
285 * The number of correspondences may vary between the individual frames (groups).<br>
286 * 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.
287 * @param pinholeCamera The pinhole camera profile for which the better field of view will be determined, must be valid
288 * @param orientations The accessor for the known orientations of the individual camera frames
289 * @param correspondenceGroups The accessor for the individual groups of point correspondences, one group for each orientation
290 * @param optimizedCamera The resulting camera profile with best matching field of view
291 * @param optimizedOrientations Optional accessor for the optimized camera orientations matching with the new camera profile
292 * @param lowerFovX The lower bound of the possible horizontal field of view in radian, with range (0, upperFovX]
293 * @param upperFovX The upper bound of the possible horizontal field of view in radian, with range [lowerFovX, PI)
294 * @param overallSteps The overall number of steps in which the defined angle range is subdivided, with range [4, infinity)
295 * @param onlyFrontObjectPoints True, to avoid that the optimized 3D position lies behind any camera
296 * @param bestError Resulting averaged square pixel error for the camera profile with the best matching field of view
297 * @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)
298 * @param lock Lock object, must be defined if this function is executed in parallel on individual threads, nullptr otherwise
299 * @param abort Optional abort statement allowing to stop the execution; True, if the execution has to stop
300 * @param firstStep The first step to be handled, with range [0, overallSteps)
301 * @param steps The number of steps which will be handled (from the entire number of overall steps), with range [1, overallSteps]
302 */
303 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);
304
305 /**
306 * 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.
307 * The number of correspondences may vary between the individual frames (groups).<br>
308 * 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.
309 * @param pinholeCamera The pinhole camera profile for which the better field of view will be determined, must be valid
310 * @param poses The accessor for the known poses of the individual camera frames
311 * @param objectPoints The accessor for the individual 3D object points
312 * @param correspondenceGroups The accessor for the individual groups of correspondences between pose ids and image point location, one group for each object point
313 * @param optimizedCamera The resulting camera profile with best matching field of view
314 * @param optimizedPoses Optional accessor for the resulting optimized camera poses matching with the new camera profile
315 * @param optimizedObjectPoints Optional accessor for the resulting optimized object point locations
316 * @param lowerFovX The lower bound of the possible horizontal field of view in radian, with range (0, upperFovX]
317 * @param upperFovX The upper bound of the possible horizontal field of view in radian, with range [lowerFovX, PI)
318 * @param overallSteps The overall number of steps in which the defined angle range is subdivided, with range [4, infinity)
319 * @param onlyFrontObjectPoints True, to avoid that the optimized 3D position lies behind any camera
320 * @param bestError Resulting averaged square pixel error for the camera profile with the best matching field of view
321 * @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)
322 * @param lock The lock object, must be defined if this function is executed in parallel on individual threads, nullptr otherwise
323 * @param abort Optional abort statement allowing to stop the execution; True, if the execution has to stop
324 * @param firstStep The first step to be handled, with range [0, overallSteps)
325 * @param steps The number of steps which will be handled (from the entire number of overall steps), with range [1, overallSteps]
326 */
327 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);
328};
329
330}
331
332}
333
334#endif // META_OCEAN_GEOMETRY_NON_LINEAR_OPTIMIZATION_CAMERA_H
This class implements the abstract base class for all AnyCamera objects.
Definition AnyCamera.h:130
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:159
This class implements an abstract specialization of the accessor for groups of pairs for poses.
Definition NonLinearOptimization.h:185
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 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, 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 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 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 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 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, 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< 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:34
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::vector< HomogenousMatrix4 > HomogenousMatrices4
Definition of a vector holding HomogenousMatrix4 objects.
Definition HomogenousMatrix4.h:73
std::shared_ptr< AnyCamera > SharedAnyCamera
Definition of a shared pointer holding an AnyCamera object with Scalar precision.
Definition AnyCamera.h:60
std::vector< Scalar > Scalars
Definition of a vector holding Scalar objects.
Definition Math.h:145
std::vector< SquareMatrix3 > SquareMatrices3
Definition of a vector holding SquareMatrix3 objects.
Definition SquareMatrix3.h:71
std::vector< Vector3 > Vectors3
Definition of a vector holding Vector3 objects.
Definition Vector3.h:65
The namespace covering the entire Ocean framework.
Definition Accessor.h:15