@@ -1212,22 +1212,21 @@ class NonLinearOptimizationCamera::CameraPosesOptimizationProvider : public NonL
12121212 /* *
12131213 * Creates a new optimization provider object.
12141214 * @param pinholeCamera The camera object to be optimized
1215- * @param posesIF Inverted and flipped extrinsic camera matrix
1215+ * @param flippedCameras_T_world The inverted and flipped camera poses to be optimized
12161216 * @param objectPointGroups Groups of 3D object points
12171217 * @param imagePointGroups Groups of 2D observation image points
12181218 * @param onlyFrontObjectPoints True, to allow only object points in front of the camera
12191219 */
1220- inline CameraPosesOptimizationProvider (PinholeCamera& pinholeCamera, NonconstTemplateArrayAccessor<HomogenousMatrix4>& posesIF , const ConstIndexedAccessor<Vectors3>& objectPointGroups, const ConstIndexedAccessor<Vectors2>& imagePointGroups, const bool onlyFrontObjectPoints) :
1220+ inline CameraPosesOptimizationProvider (PinholeCamera& pinholeCamera, NonconstTemplateArrayAccessor<HomogenousMatrix4>& flippedCameras_T_world , const ConstIndexedAccessor<Vectors3>& objectPointGroups, const ConstIndexedAccessor<Vectors2>& imagePointGroups, const bool onlyFrontObjectPoints) :
12211221 camera_(pinholeCamera),
12221222 candidateCamera_(pinholeCamera),
1223- flippedCamera_T_world_(posesIF ),
1223+ flippedCameras_T_world_(flippedCameras_T_world ),
12241224 objectPointGroups_(objectPointGroups),
1225- candidateFlippedCamera_T_world_ (Accessor::accessor2elements(posesIF )),
1225+ candidateFlippedCameras_T_world_ (Accessor::accessor2elements(flippedCameras_T_world )),
12261226 imagePointGroups_(imagePointGroups),
1227- onlyFrontObjectPoints_(onlyFrontObjectPoints),
1228- observations_(0 )
1227+ onlyFrontObjectPoints_(onlyFrontObjectPoints)
12291228 {
1230- ocean_assert (flippedCamera_T_world_ .size () == objectPointGroups_.size ());
1229+ ocean_assert (flippedCameras_T_world_ .size () == objectPointGroups_.size ());
12311230 ocean_assert (objectPointGroups_.size () == imagePointGroups_.size ());
12321231
12331232 for (size_t n = 0 ; n < objectPointGroups_.size (); ++n)
@@ -1263,19 +1262,19 @@ class NonLinearOptimizationCamera::CameraPosesOptimizationProvider : public NonL
12631262 Scalar jacobianX[14 ], jacobianY[14 ];
12641263 size_t row = 0 ;
12651264
1266- for (size_t p = 0 ; p < flippedCamera_T_world_ .size (); ++p)
1265+ for (size_t p = 0 ; p < flippedCameras_T_world_ .size (); ++p)
12671266 {
1268- const HomogenousMatrix4& transformationPoseIF = flippedCamera_T_world_ [p];
1267+ const HomogenousMatrix4& flippedCamera_T_world = flippedCameras_T_world_ [p];
12691268 const Vectors3& objectPoints = objectPointGroups_[p];
12701269
1271- const Pose poseIF (transformationPoseIF );
1270+ const Pose flippedCamera_P_world (flippedCamera_T_world );
12721271
12731272 SquareMatrix3 Rwx, Rwy, Rwz;
1274- Jacobian::calculateRotationRodriguesDerivative (ExponentialMap (Vector3 (poseIF .rx (), poseIF .ry (), poseIF .rz ())), Rwx, Rwy, Rwz);
1273+ Jacobian::calculateRotationRodriguesDerivative (ExponentialMap (Vector3 (flippedCamera_P_world .rx (), flippedCamera_P_world .ry (), flippedCamera_P_world .rz ())), Rwx, Rwy, Rwz);
12751274
12761275 for (size_t i = 0 ; i < objectPoints.size (); ++i)
12771276 {
1278- Jacobian::calculateJacobianCameraPoseRodrigues2x14 (jacobianX, jacobianY, camera_, transformationPoseIF, poseIF , objectPoints[i], Rwx, Rwy, Rwz);
1277+ Jacobian::calculateJacobianCameraPoseRodrigues2x14 (jacobianX, jacobianY, camera_, flippedCamera_T_world, flippedCamera_P_world , objectPoints[i], Rwx, Rwy, Rwz);
12791278
12801279 for (size_t e = 0u ; e < 8u ; ++e)
12811280 {
@@ -1299,7 +1298,7 @@ class NonLinearOptimizationCamera::CameraPosesOptimizationProvider : public NonL
12991298
13001299 ocean_assert (row == observations_ * 2 );
13011300
1302- jacobian = SparseMatrix (2 * observations_, 8 + flippedCamera_T_world_ .size () * 6 , jacobianEntries);
1301+ jacobian = SparseMatrix (2 * observations_, 8 + flippedCameras_T_world_ .size () * 6 , jacobianEntries);
13031302 ocean_assert (SparseMatrix::Entry::hasOneEntry (jacobian.rows (), jacobian.columns (), jacobianEntries));
13041303 }
13051304
@@ -1329,14 +1328,14 @@ class NonLinearOptimizationCamera::CameraPosesOptimizationProvider : public NonL
13291328
13301329 candidateCamera_ = PinholeCamera (SquareMatrix3 (newFx, 0 , 0 , 0 , newFy, 0 , newMx, newMy, 1 ), camera_.width (), camera_.height (), PinholeCamera::DistortionPair (newK1, newK2), PinholeCamera::DistortionPair (newP1, newP2));
13311330
1332- for (size_t n = 0 ; n < flippedCamera_T_world_ .size (); ++n)
1331+ for (size_t n = 0 ; n < flippedCameras_T_world_ .size (); ++n)
13331332 {
1334- const Pose pose (flippedCamera_T_world_ [n]);
1333+ const Pose pose (flippedCameras_T_world_ [n]);
13351334
13361335 const Pose deltaPose (deltas (8 + n * 6 + 3 ), deltas (8 + n * 6 + 4 ), deltas (8 + n * 6 + 5 ), deltas (8 + n * 6 + 0 ), deltas (8 + n * 6 + 1 ), deltas (8 + n * 6 + 2 ));
13371336 const Pose newPose (pose - deltaPose);
13381337
1339- candidateFlippedCamera_T_world_ [n] = newPose.transformation ();
1338+ candidateFlippedCameras_T_world_ [n] = newPose.transformation ();
13401339 }
13411340 }
13421341
@@ -1368,22 +1367,22 @@ class NonLinearOptimizationCamera::CameraPosesOptimizationProvider : public NonL
13681367 size_t row = 0 ;
13691368 Scalar sqrError = 0 ;
13701369
1371- for (size_t p = 0 ; p < flippedCamera_T_world_ .size (); ++p)
1370+ for (size_t p = 0 ; p < flippedCameras_T_world_ .size (); ++p)
13721371 {
1373- const HomogenousMatrix4& poseIF = candidateFlippedCamera_T_world_ [p];
1372+ const HomogenousMatrix4& candidateFlippedCamera_T_world = candidateFlippedCameras_T_world_ [p];
13741373 const Vectors3& objectPoints = objectPointGroups_[p];
13751374 const Vectors2& imagePoints = imagePointGroups_[p];
13761375
13771376 for (size_t i = 0 ; i < objectPoints.size (); ++i)
13781377 {
13791378 const Vector3& objectPoint = objectPoints[i];
13801379
1381- if (onlyFrontObjectPoints_ && !PinholeCamera::isObjectPointInFrontIF (poseIF , objectPoint))
1380+ if (onlyFrontObjectPoints_ && !PinholeCamera::isObjectPointInFrontIF (candidateFlippedCamera_T_world , objectPoint))
13821381 {
13831382 return Numeric::maxValue ();
13841383 }
13851384
1386- const Vector2 error = Error::determinePoseErrorIF (poseIF , candidateCamera_, objectPoint, imagePoints[i], true );
1385+ const Vector2 error = Error::determinePoseErrorIF (candidateFlippedCamera_T_world , candidateCamera_, objectPoint, imagePoints[i], true );
13871386 weightedErrors[row++] = error;
13881387
13891388 if constexpr (Estimator::isStandardEstimator<tEstimator>())
@@ -1416,7 +1415,7 @@ class NonLinearOptimizationCamera::CameraPosesOptimizationProvider : public NonL
14161415 ocean_assert (sqrErrors.size () == observations_);
14171416
14181417 // the model size is the number of columns in the jacobian row as so many parameters will be modified
1419- return sqrErrors2robustErrors2<tEstimator>(sqrErrors, 8 + flippedCamera_T_world_ .size () * 6 , weightedErrors, (Vector2*)(weightVector.data ()), transposedInvertedCovariances);
1418+ return sqrErrors2robustErrors2<tEstimator>(sqrErrors, 8 + flippedCameras_T_world_ .size () * 6 , weightedErrors, (Vector2*)(weightVector.data ()), transposedInvertedCovariances);
14201419 }
14211420 }
14221421
@@ -1427,10 +1426,10 @@ class NonLinearOptimizationCamera::CameraPosesOptimizationProvider : public NonL
14271426 {
14281427 camera_ = candidateCamera_;
14291428
1430- ocean_assert (flippedCamera_T_world_ .size () == candidateFlippedCamera_T_world_ .size ());
1431- for (size_t n = 0 ; n < flippedCamera_T_world_ .size (); ++n)
1429+ ocean_assert (flippedCameras_T_world_ .size () == candidateFlippedCameras_T_world_ .size ());
1430+ for (size_t n = 0 ; n < flippedCameras_T_world_ .size (); ++n)
14321431 {
1433- flippedCamera_T_world_ [n] = candidateFlippedCamera_T_world_ [n];
1432+ flippedCameras_T_world_ [n] = candidateFlippedCameras_T_world_ [n];
14341433 }
14351434 }
14361435
@@ -1443,13 +1442,13 @@ class NonLinearOptimizationCamera::CameraPosesOptimizationProvider : public NonL
14431442 PinholeCamera candidateCamera_;
14441443
14451444 // / The accessor for all camera poses.
1446- NonconstTemplateArrayAccessor<HomogenousMatrix4>& flippedCamera_T_world_ ;
1445+ NonconstTemplateArrayAccessor<HomogenousMatrix4>& flippedCameras_T_world_ ;
14471446
14481447 // / The accessor for all object point groups.
14491448 const ConstIndexedAccessor<Vectors3>& objectPointGroups_;
14501449
14511450 // / The candidates of new camera poses.
1452- HomogenousMatrices4 candidateFlippedCamera_T_world_ ;
1451+ HomogenousMatrices4 candidateFlippedCameras_T_world_ ;
14531452
14541453 // / The accessor for all image point groups.
14551454 const ConstIndexedAccessor<Vectors2>& imagePointGroups_;
@@ -1458,7 +1457,7 @@ class NonLinearOptimizationCamera::CameraPosesOptimizationProvider : public NonL
14581457 const bool onlyFrontObjectPoints_;
14591458
14601459 // The entire number of observations.
1461- size_t observations_;
1460+ size_t observations_ = 0 ;
14621461};
14631462
14641463bool NonLinearOptimizationCamera::optimizeCameraPoses (const PinholeCamera& pinholeCamera, const ConstIndexedAccessor<HomogenousMatrix4>& poses, const ConstIndexedAccessor<Vectors3>& objectPointGroups, const ConstIndexedAccessor<Vectors2>& imagePointGroups, PinholeCamera& optimizedCamera, NonconstIndexedAccessor<HomogenousMatrix4>* optimizedPoses, const unsigned int iterations, const Estimator::EstimatorType estimator, Scalar lambda, const Scalar lambdaFactor, const bool onlyFrontObjectPoints, Scalar* initialError, Scalar* finalError, Scalars* intermediateErrors)
0 commit comments