MCPcopy Create free account
hub / github.com/UZ-SLAMLab/ORB_SLAM3 / CorrectLoop

Method CorrectLoop

src/LoopClosing.cc:969–1213  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

967}
968
969void LoopClosing::CorrectLoop()
970{
971 //cout << "Loop detected!" << endl;
972
973 // Send a stop signal to Local Mapping
974 // Avoid new keyframes are inserted while correcting the loop
975 mpLocalMapper->RequestStop();
976 mpLocalMapper->EmptyQueue(); // Proccess keyframes in the queue
977
978 // If a Global Bundle Adjustment is running, abort it
979 if(isRunningGBA())
980 {
981 cout << "Stoping Global Bundle Adjustment...";
982 unique_lock<mutex> lock(mMutexGBA);
983 mbStopGBA = true;
984
985 mnFullBAIdx++;
986
987 if(mpThreadGBA)
988 {
989 mpThreadGBA->detach();
990 delete mpThreadGBA;
991 }
992 cout << " Done!!" << endl;
993 }
994
995 // Wait until Local Mapping has effectively stopped
996 while(!mpLocalMapper->isStopped())
997 {
998 usleep(1000);
999 }
1000
1001 // Ensure current keyframe is updated
1002 //cout << "Start updating connections" << endl;
1003 //assert(mpCurrentKF->GetMap()->CheckEssentialGraph());
1004 mpCurrentKF->UpdateConnections();
1005 //assert(mpCurrentKF->GetMap()->CheckEssentialGraph());
1006
1007 // Retrive keyframes connected to the current keyframe and compute corrected Sim3 pose by propagation
1008 mvpCurrentConnectedKFs = mpCurrentKF->GetVectorCovisibleKeyFrames();
1009 mvpCurrentConnectedKFs.push_back(mpCurrentKF);
1010
1011 //std::cout << "Loop: number of connected KFs -> " + to_string(mvpCurrentConnectedKFs.size()) << std::endl;
1012
1013 KeyFrameAndPose CorrectedSim3, NonCorrectedSim3;
1014 CorrectedSim3[mpCurrentKF]=mg2oLoopScw;
1015 Sophus::SE3f Twc = mpCurrentKF->GetPoseInverse();
1016 Sophus::SE3f Tcw = mpCurrentKF->GetPose();
1017 g2o::Sim3 g2oScw(Tcw.unit_quaternion().cast<double>(),Tcw.translation().cast<double>(),1.0);
1018 NonCorrectedSim3[mpCurrentKF]=g2oScw;
1019
1020 // Update keyframe pose with corrected Sim3. First transform Sim3 to SE3 (scale translation)
1021 Sophus::SE3d correctedTcw(mg2oLoopScw.rotation(),mg2oLoopScw.translation() / mg2oLoopScw.scale());
1022 mpCurrentKF->SetPose(correctedTcw.cast<float>());
1023
1024 Map* pLoopMap = mpCurrentKF->GetMap();
1025
1026#ifdef REGISTER_TIMES

Callers

nothing calls this directly

Calls 15

EmptyQueueMethod · 0.80
UpdateConnectionsMethod · 0.80
GetPoseInverseMethod · 0.80
scaleMethod · 0.80
GetMapPointMatchesMethod · 0.80
GetWorldPosMethod · 0.80
SetWorldPosMethod · 0.80
UpdateNormalAndDepthMethod · 0.80
IncreaseChangeIndexMethod · 0.80
GetCurrentMapMethod · 0.80
GetMapPointMethod · 0.80

Tested by

no test coverage detected