@@ -1559,7 +1559,13 @@ std::map<int, Transform> OptimizerG2O::optimizeBA(
15591559#endif // RTABMAP_ORB_SLAM
15601560
15611561#ifndef RTABMAP_ORB_SLAM
1562- if (optimizer_ == 1 )
1562+ // ISSUE: It seems the fatal error
1563+ // "[SetJac] infinite jac" happens relatively
1564+ // easily with GaussNewton on SBA problem,
1565+ // ignore optimizer_ and always use Levenberg for SBA.
1566+ // TODO: Note that g2o/RobustKernelDelta parameter could be
1567+ // potentially tuned to avoid that error with GaussNewton.
1568+ if (0 )// optimizer_ == 1)
15631569 {
15641570#ifdef RTABMAP_G2O_CPP11
15651571 optimizer.setAlgorithm (new g2o::OptimizationAlgorithmGaussNewton (
@@ -1944,7 +1950,8 @@ std::map<int, Transform> OptimizerG2O::optimizeBA(
19441950
19451951 if (uIsNan (chi2))
19461952 {
1947- UERROR (" Optimization generated NANs, aborting optimization! Try another g2o's optimizer (current=%d)." , optimizer_);
1953+ UERROR (" Optimization generated NANs, aborting optimization! Try another g2o's optimizer (current %s=%d) or solver (current %s=%d)." ,
1954+ Parameters::kg2oOptimizer ().c_str (), optimizer_, Parameters::kg2oSolver ().c_str (), solver_);
19481955 return optimizedPoses;
19491956 }
19501957 UDEBUG (" iteration %d: %d nodes, %d edges, chi2: %f" , i, (int )optimizer.vertices ().size (), (int )optimizer.edges ().size (), chi2);
@@ -1978,15 +1985,18 @@ std::map<int, Transform> OptimizerG2O::optimizeBA(
19781985 // UDEBUG("Ignoring edge (%d<->%d) d=%f var=%f kernel=%f chi2=%f", (*iter)->vertex(0)->id()-stepVertexId, (*iter)->vertex(1)->id(), d, 1.0/((g2o::EdgeProjectP2SC*)(*iter))->information()(0,0), (*iter)->robustKernel()->delta(), (*iter)->chi2());
19791986#endif
19801987
1981- cv::Point3f pt3d ;
1988+ int id=- 1 ;
19821989 if ((*iter)->vertex (0 )->id () > negVertexOffset)
19831990 {
1984- pt3d = points3DMap. at ( negVertexOffset - (*iter)->vertex (0 )->id () );
1991+ id = negVertexOffset - (*iter)->vertex (0 )->id ();
19851992 }
19861993 else
19871994 {
1988- pt3d = points3DMap. at (( *iter)->vertex (0 )->id ()- stepVertexId) ;
1995+ id = ( *iter)->vertex (0 )->id () - stepVertexId;
19891996 }
1997+ UASSERT_MSG (points3DMap.find (id) != points3DMap.end (), uFormat (" word id=%d points3DMap=%ld vertex id=%d (negVertexOffset=%d stepVertexId=%d)" ,
1998+ id, points3DMap.size (), (*iter)->vertex (0 )->id (), negVertexOffset, stepVertexId).c_str ());
1999+ cv::Point3f pt3d = points3DMap.at (id);
19902000 ((g2o::VertexSBAPointXYZ*)(*iter)->vertex (0 ))->setEstimate (Eigen::Vector3d (pt3d.x , pt3d.y , pt3d.z ));
19912001
19922002 if (outliers)
0 commit comments