6                                 ORB_SLAM2::KPextractor* kpIniExtractor,
 
   10                                 std::string             orbVocFile,
 
   11                                 bool                    applyMinAccScoreFilter)
 
   12   : mpExtractor(kpExtractor),
 
   13     mpIniExtractor(kpIniExtractor),
 
   15     _applyMinAccScoreFilter(applyMinAccScoreFilter)
 
   28     if (!WAIOrbVocabulary::initialize(orbVocFile))
 
   29         throw std::runtime_error(
"ModeOrbSlam2: could not find vocabulary file: " + orbVocFile);
 
   57     _pose  = cv::Mat(4, 4, CV_32F);
 
   61                                 ORB_SLAM2::KPextractor* kpIniExtractor,
 
   62                                 ORB_SLAM2::KPextractor* kpMarkerExtractor,
 
   63                                 std::string             markerFile,
 
   65                                 cv::Mat                 distortionMat,
 
   67                                 std::string             orbVocFile,
 
   68                                 bool                    applyMinAccScoreFilter)
 
   69   : mpExtractor(kpExtractor),
 
   70     mpIniExtractor(kpIniExtractor),
 
   71     _markerExtractor(kpMarkerExtractor),
 
   73     _applyMinAccScoreFilter(applyMinAccScoreFilter)
 
   86     if (!WAIOrbVocabulary::initialize(orbVocFile))
 
   87         throw std::runtime_error(
"ModeOrbSlam2: could not find vocabulary file: " + orbVocFile);
 
  115     _pose  = cv::Mat(4, 4, CV_32F);
 
  124     WAIOrbVocabulary::free();
 
  125     WAIOrbVocabulary::initialize(orbVocFile);
 
  127     mpKeyFrameDatabase->changeVocabulary(*mpVocabulary, getKeyFrames());
 
  129         mpLocalMapper->SetVocabulary(mpVocabulary);
 
  131         mpLoopCloser->SetVocabulary(mpVocabulary);
 
  139         mpLocalMapper->RequestFinish();
 
  141         mpLoopCloser->RequestFinish();
 
  144         mptLocalMapping->join();
 
  146             mptLoopClosing->join();
 
  149     if (mpLocalMapper) 
delete mpLocalMapper;
 
  150     if (mpLoopCloser) 
delete mpLoopCloser;
 
  175             initialize(imageGray, imageRGB);
 
  183             track3DPts(imageGray, imageRGB);
 
  200     int result = _map->MapPointsInMap();
 
  207     int result = mnMatchesInliers;
 
  214     int result = _map->KeyFramesInMap();
 
  221     std::string result = mpLoopCloser->getStatusString();
 
  228     int result = _map->getNumLoopClosings();
 
  235     int result = mpLoopCloser->numOfKfsInQueue();
 
  242     std::lock_guard<std::mutex> guard(_nMapMatchesLock);
 
  243     return mnMatchesInliers;
 
  248     std::lock_guard<std::mutex> guard(_mapLock);
 
  249     return _map->KeyFramesInMap();
 
  254     std::lock_guard<std::mutex> guard(_poseDiffLock);
 
  255     return _poseDifference;
 
  260     return _meanReprojectionError;
 
  265     std::string printableState = 
"";
 
  271             printableState = 
"INITIALIZING";
 
  277             printableState = 
"IDLE";
 
  283             printableState = 
"TRACKING_LOST"; 
 
  289             printableState = 
"TRACKING_OK";
 
  295             printableState = 
"TRACKING_NONE";
 
  306     return printableState;
 
  311     switch (_trackingType)
 
  313         case TrackingType_MotionModel:
 
  314             return "Motion Model";
 
  315         case TrackingType_OptFlow:
 
  316             return "Optical Flow";
 
  317         case TrackingType_ORBSLAM:
 
  319         case TrackingType_None:
 
  327     std::lock_guard<std::mutex> guard(_mapLock);
 
  329     std::vector<WAIMapPoint*> result = _map->GetAllMapPoints();
 
  336     std::vector<WAIMapPoint*> result;
 
  344         result.push_back(_mpUL);
 
  352         result.push_back(_mpUR);
 
  360         result.push_back(_mpLL);
 
  368         result.push_back(_mpLR);
 
  376     std::lock_guard<std::mutex> guard(_mapLock);
 
  378     std::vector<WAIMapPoint*> result;
 
  382         result = _optFlowMapPtsLastFrame;
 
  386         for (
int i = 0; i < mCurrentFrame.N; i++)
 
  388             if (mCurrentFrame.mvpMapPoints[i])
 
  390                 if (mCurrentFrame.mvpMapPoints[i]->Observations() > 0)
 
  391                     result.push_back(mCurrentFrame.mvpMapPoints[i]);
 
  401     std::lock_guard<std::mutex> guard(_mapLock);
 
  403     std::vector<cv::Vec3f> points3d;
 
  404     std::vector<cv::Vec2f> points2d;
 
  406     for (
int i = 0; i < mCurrentFrame.N; i++)
 
  418                 points3d.push_back(v);
 
  419                 points2d.push_back(mCurrentFrame.mvKeysUn[i].pt);
 
  424     return std::pair<std::vector<cv::Vec3f>, std::vector<cv::Vec2f>>(points3d, points2d);
 
  429     std::lock_guard<std::mutex> guard(_mapLock);
 
  431     std::vector<cv::Vec3f> points3d;
 
  432     std::vector<cv::Vec2f> points2d;
 
  434     for (
int i = 0; i < mCurrentFrame.N; i++)
 
  444             points3d.push_back(v);
 
  445             points2d.push_back(mCurrentFrame.mvKeys[i].pt);
 
  449     return std::pair<std::vector<cv::Vec3f>, std::vector<cv::Vec2f>>(points3d, points2d);
 
  454     std::lock_guard<std::mutex> guard(_mapLock);
 
  455     std::vector<WAIMapPoint*>   result = mvpLocalMapPoints;
 
  462     std::lock_guard<std::mutex> guard(_mapLock);
 
  463     std::vector<WAIKeyFrame*>   result = _map->GetAllKeyFrames();
 
  470     std::lock_guard<std::mutex> guard(_optFlowLock);
 
  471     return _params.trackOptFlow;
 
  476     std::lock_guard<std::mutex> guard(_optFlowLock);
 
  477     _params.trackOptFlow = flag;
 
  483     _params.onlyTracking = 
true;
 
  486         mpLocalMapper->RequestStop();
 
  487         while (!mpLocalMapper->isStopped())
 
  489             std::this_thread::sleep_for(std::chrono::microseconds(10));
 
  492     mpLocalMapper->InterruptBA();
 
  497     _params.onlyTracking = 
false;
 
  503     std::lock_guard<std::mutex> guard(_mutexStates);
 
  511         _idleRequested = 
false;
 
  515         if (_resumeRequested)
 
  526             _resumeRequested = 
false;
 
  574     int matchesNeeded = 100;
 
  577     std::unique_lock<std::mutex> lock(_map->mMutexMapUpdate, std::defer_lock);
 
  597         if (_createMarkerMap)
 
  599             ORBmatcher               matcher(0.9, 
true);
 
  600             std::vector<cv::Point2f> prevMatched(_markerFrame.mvKeysUn.size());
 
  601             for (
size_t i = 0; i < _markerFrame.mvKeysUn.size(); i++)
 
  602                 prevMatched[i] = _markerFrame.mvKeysUn[i].pt;
 
  604             std::vector<int> markerMatchesToCurrentFrame;
 
  605             int              nmatches = matcher.SearchForInitialization(_markerFrame, mCurrentFrame, prevMatched, markerMatchesToCurrentFrame, 100);
 
  615         if (mCurrentFrame.mvKeys.size() > matchesNeeded)
 
  617             mInitialFrame = 
WAIFrame(mCurrentFrame);
 
  618             mLastFrame    = 
WAIFrame(mCurrentFrame);
 
  619             mvbPrevMatched.resize(mCurrentFrame.mvKeysUn.size());
 
  622             for (
size_t i = 0; i < mCurrentFrame.mvKeysUn.size(); i++)
 
  623                 mvbPrevMatched[i] = mCurrentFrame.mvKeysUn[i].pt;
 
  627                 delete mpInitializer;
 
  629             mpInitializer = 
new ORB_SLAM2::Initializer(mCurrentFrame, 1.0, 200);
 
  631             fill(mvIniMatches.begin(), mvIniMatches.end(), -1);
 
  639         if ((
int)mCurrentFrame.mvKeys.size() <= matchesNeeded)
 
  641             delete mpInitializer;
 
  642             mpInitializer = 
static_cast<Initializer*
>(NULL);
 
  643             fill(mvIniMatches.begin(), mvIniMatches.end(), -1);
 
  648         ORBmatcher matcher(0.9, 
true);
 
  649         int        nmatches = matcher.SearchForInitialization(mInitialFrame, mCurrentFrame, mvbPrevMatched, mvIniMatches, 100);
 
  652         if (nmatches < matchesNeeded)
 
  654             delete mpInitializer;
 
  655             mpInitializer = 
static_cast<Initializer*
>(NULL);
 
  659         for (
unsigned int i = 0; i < mInitialFrame.mvKeys.size(); i++)
 
  661             cv::rectangle(imageRGB,
 
  662                           mInitialFrame.mvKeys[i].pt,
 
  663                           cv::Point(mInitialFrame.mvKeys[i].pt.x + 3, mInitialFrame.mvKeys[i].pt.y + 3),
 
  664                           cv::Scalar(0, 0, 255));
 
  668         for (
unsigned int i = 0; i < mvIniMatches.size(); i++)
 
  670             if (mvIniMatches[i] >= 0)
 
  673                          mInitialFrame.mvKeys[i].pt,
 
  674                          mCurrentFrame.mvKeys[mvIniMatches[i]].pt,
 
  675                          cv::Scalar(0, 255, 0));
 
  681         vector<bool> vbTriangulated; 
 
  683         if (mpInitializer->Initialize(mCurrentFrame, mvIniMatches, Rcw, tcw, mvIniP3D, vbTriangulated))
 
  689             for (
size_t i = 0, iend = mvIniMatches.size(); i < iend; i++)
 
  691                 if (mvIniMatches[i] >= 0 && !vbTriangulated[i])
 
  693                     mvIniMatches[i] = -1;
 
  703             mInitialFrame.SetPose(cv::Mat::eye(4, 4, CV_32F));
 
  704             cv::Mat Tcw = cv::Mat::eye(4, 4, CV_32F);
 
  705             Rcw.copyTo(Tcw.rowRange(0, 3).colRange(0, 3));
 
  706             tcw.copyTo(Tcw.rowRange(0, 3).col(3));
 
  707             mCurrentFrame.SetPose(Tcw);
 
  709             bool mapInitializedSuccessfully = createInitialMapMonocular(matchesNeeded);
 
  711             if (mapInitializedSuccessfully)
 
  720             if (!mCurrentFrame.mTcw.empty() && mCurrentFrame.mpReferenceKF)
 
  722                 cv::Mat Tcr = mCurrentFrame.mTcw * mCurrentFrame.mpReferenceKF->GetPoseInverse();
 
  723                 mlRelativeFramePoses.push_back(Tcr);
 
  724                 mlpReferences.push_back(mpReferenceKF);
 
  725                 mlFrameTimes.push_back(mCurrentFrame.mTimeStamp);
 
  728             else if (mlRelativeFramePoses.size())
 
  731                 mlRelativeFramePoses.push_back(mlRelativeFramePoses.back());
 
  732                 mlpReferences.push_back(mlpReferences.back());
 
  733                 mlFrameTimes.push_back(mlFrameTimes.back());
 
  742     posX = (int)round((kp.pt.x - minX) * _optFlowGridElementWidthInv);
 
  743     posY = (int)round((kp.pt.y - minY) * _optFlowGridElementHeightInv);
 
  763     std::unique_lock<std::mutex> lock(_map->mMutexMapUpdate, std::defer_lock);
 
  774     if (!_params.onlyTracking)
 
  782             checkReplacedInLastFrame();
 
  784             if (mVelocity.empty() || mCurrentFrame.mnId < mnLastRelocFrameId + 2)
 
  786                 _bOK = trackReferenceKeyFrame();
 
  791                 _bOK = trackWithMotionModel();
 
  796                     _bOK = trackReferenceKeyFrame();
 
  803             _bOK = relocalization(mCurrentFrame, mpKeyFrameDatabase, &mnLastRelocFrameId, *_map, _applyMinAccScoreFilter, 
false);
 
  811             _bOK       = relocalization(mCurrentFrame, mpKeyFrameDatabase, &mnLastRelocFrameId, *_map, _applyMinAccScoreFilter);
 
  820                 if (!mVelocity.empty())
 
  823                     _bOK = trackWithMotionModel();
 
  834                     _bOK = trackReferenceKeyFrame();
 
  845                 bool                 bOKReloc = 
false;
 
  846                 vector<WAIMapPoint*> vpMPsMM;
 
  847                 vector<bool>         vbOutMM;
 
  849                 if (!mVelocity.empty())
 
  851                     bOKMM   = trackWithMotionModel();
 
  852                     vpMPsMM = mCurrentFrame.mvpMapPoints;
 
  853                     TcwMM   = mCurrentFrame.mTcw.clone();
 
  855                 bOKReloc = relocalization(mCurrentFrame, mpKeyFrameDatabase, &mnLastRelocFrameId, *_map, _applyMinAccScoreFilter);
 
  857                 if (bOKMM && !bOKReloc)
 
  859                     mCurrentFrame.SetPose(TcwMM);
 
  860                     mCurrentFrame.mvpMapPoints = vpMPsMM;
 
  864                         for (
int i = 0; i < mCurrentFrame.N; i++)
 
  867                             if (mCurrentFrame.mvpMapPoints[i])
 
  869                                 mCurrentFrame.mvpMapPoints[i]->IncreaseFound();
 
  879                 _bOK = bOKReloc || bOKMM;
 
  886     if (!_params.onlyTracking)
 
  891             _bOK = trackLocalMap();
 
  900             _bOK = trackLocalMap();
 
  907         _optFlowOK = trackWithOptFlow();
 
  919         if (!mLastFrame.mTcw.empty())
 
  922             cv::Mat LastTwc = cv::Mat::eye(4, 4, CV_32F);
 
  924             mLastFrame.GetRotationInverse().copyTo(LastTwc.rowRange(0, 3).colRange(0, 3)); 
 
  926             const auto& cc = mLastFrame.GetCameraCenter(); 
 
  928             cc.copyTo(LastTwc.rowRange(0, 3).col(3));
 
  931             mVelocity = mCurrentFrame.mTcw * LastTwc;
 
  935             mVelocity = cv::Mat();
 
  943                 Tcw = _optFlowTcw.clone();
 
  947                 Tcw = mCurrentFrame.mTcw.clone();
 
  971         if (needNewKeyFrame())
 
  978                 mpLocalMapper->RunOnce();
 
  984                 mpLoopCloser->RunOnce();
 
  989             _mapHasChanged = 
true;
 
 1007     if (!mCurrentFrame.mpReferenceKF)
 
 1009         mCurrentFrame.mpReferenceKF = mpReferenceKF;
 
 1014     mLastFrame = 
WAIFrame(mCurrentFrame);
 
 1017     if (mCurrentFrame.mpReferenceKF && !mCurrentFrame.mTcw.empty())
 
 1019         cv::Mat Tcr = mCurrentFrame.mTcw * mCurrentFrame.mpReferenceKF->GetPoseInverse(); 
 
 1021         mlRelativeFramePoses.push_back(Tcr);
 
 1022         mlpReferences.push_back(mpReferenceKF);
 
 1023         mlFrameTimes.push_back(mCurrentFrame.mTimeStamp);
 
 1026     else if (mlRelativeFramePoses.size() && mlpReferences.size() && mlFrameTimes.size())
 
 1029         mlRelativeFramePoses.push_back(mlRelativeFramePoses.back());
 
 1030         mlpReferences.push_back(mlpReferences.back());
 
 1031         mlFrameTimes.push_back(mlFrameTimes.back());
 
 1052     _map->AddKeyFrame(pKFini);
 
 1053     _map->AddKeyFrame(pKFcur);
 
 1056     for (
size_t i = 0; i < mvIniMatches.size(); i++)
 
 1058         if (mvIniMatches[i] < 0)
 
 1062         cv::Mat worldPos(mvIniP3D[i]);
 
 1076         mCurrentFrame.mvpMapPoints[mvIniMatches[i]] = pMP;
 
 1079         _map->AddMapPoint(pMP);
 
 1089     Optimizer::GlobalBundleAdjustemnt(_map, 20);
 
 1093     float invMedianDepth = 1.0f / medianDepth;
 
 1095     if (medianDepth < 0 || pKFcur->TrackedMapPoints(1) < mapPointsNeeded)
 
 1097         Utils::log(
"WAI", 
"Wrong initialization, reseting...");
 
 1103     cv::Mat Tc2w               = pKFcur->
GetPose();
 
 1104     Tc2w.col(3).rowRange(0, 3) = Tc2w.col(3).rowRange(0, 3) * invMedianDepth;
 
 1109     for (
size_t iMP = 0; iMP < vpAllMapPoints.size(); iMP++)
 
 1111         if (vpAllMapPoints[iMP])
 
 1118     mpLocalMapper->InsertKeyFrame(pKFini);
 
 1119     mpLocalMapper->InsertKeyFrame(pKFcur);
 
 1121     mCurrentFrame.SetPose(pKFcur->
GetPose());
 
 1122     mnLastKeyFrameId = mCurrentFrame.mnId;
 
 1123     mpLastKeyFrame   = pKFcur;
 
 1125     mvpLocalKeyFrames.push_back(pKFcur);
 
 1126     mvpLocalKeyFrames.push_back(pKFini);
 
 1127     mvpLocalMapPoints = _map->GetAllMapPoints();
 
 1129     mpReferenceKF               = pKFcur;
 
 1130     mCurrentFrame.mpReferenceKF = pKFcur;
 
 1132     mLastFrame = 
WAIFrame(mCurrentFrame);
 
 1134     _map->SetReferenceMapPoints(mvpLocalMapPoints);
 
 1136     _map->mvpKeyFrameOrigins.push_back(pKFini);
 
 1141         mpLocalMapper->RunOnce();
 
 1143         mpLocalMapper->RunOnce();
 
 1151     _mapHasChanged = 
true;
 
 1157     for (
int i = 0; i < mLastFrame.N; i++)
 
 1166                 mLastFrame.mvpMapPoints[i] = pRep;
 
 1174     if (_params.onlyTracking)
 
 1178     if (mpLocalMapper->isStopped() || mpLocalMapper->stopRequested())
 
 1181     const int nKFs = _map->KeyFramesInMap();
 
 1185     if (mCurrentFrame.mnId < mnLastRelocFrameId + mMaxFrames && nKFs > mMaxFrames)
 
 1192     int nRefMatches = mpReferenceKF->TrackedMapPoints(nMinObs);
 
 1195     bool bLocalMappingIdle = mpLocalMapper->AcceptKeyFrames();
 
 1198     float thRefRatio = 0.9f;
 
 1203     const bool c1a = mCurrentFrame.mnId >= mnLastKeyFrameId + mMaxFrames;
 
 1205     const bool c1b = (mCurrentFrame.mnId >= mnLastKeyFrameId + mMinFrames && bLocalMappingIdle);
 
 1207     const bool c2 = ((mnMatchesInliers < nRefMatches * thRefRatio) && mnMatchesInliers > 15);
 
 1209     if ((c1a || c1b) && c2)
 
 1213         if (bLocalMappingIdle)
 
 1219             mpLocalMapper->InterruptBA();
 
 1231     if (!mpLocalMapper->SetNotStop(
true))
 
 1236     mpReferenceKF               = pKF;
 
 1237     mCurrentFrame.mpReferenceKF = pKF;
 
 1238     mpLocalMapper->InsertKeyFrame(pKF);
 
 1240     mpLocalMapper->SetNotStop(
false);
 
 1242     mnLastKeyFrameId = mCurrentFrame.
mnId;
 
 1243     mpLastKeyFrame   = pKF;
 
 1251     if (!_params.serial)
 
 1253         mpLocalMapper->RequestReset();
 
 1257         mpLocalMapper->reset();
 
 1261     if (!_params.serial)
 
 1264         mpLoopCloser->RequestReset();
 
 1268         mpLoopCloser->reset();
 
 1272     mpKeyFrameDatabase->clear();
 
 1283     _initialized = 
false;
 
 1287         delete mpInitializer;
 
 1288         mpInitializer = 
static_cast<Initializer*
>(
nullptr);
 
 1291     mlRelativeFramePoses.clear();
 
 1292     mlpReferences.clear();
 
 1293     mlFrameTimes.clear();
 
 1297     mpLastKeyFrame = 
nullptr;
 
 1298     mpReferenceKF  = 
nullptr;
 
 1299     mvpLocalMapPoints.clear();
 
 1300     mvpLocalKeyFrames.clear();
 
 1301     mnMatchesInliers   = 0;
 
 1302     mnLastKeyFrameId   = 0;
 
 1303     mnLastRelocFrameId = 0;
 
 1310     bool result = _initialized;
 
 1317     if (!_params.serial)
 
 1319         mpLocalMapper->RequestStop();
 
 1320         while (!mpLocalMapper->isStopped())
 
 1322             std::this_thread::sleep_for(std::chrono::microseconds(10));
 
 1327     while (!hasStateIdle())
 
 1329         std::this_thread::sleep_for(std::chrono::microseconds(10));
 
 1335     if (!_params.serial)
 
 1337         mpLocalMapper->Release();
 
 1348         std::unique_lock<std::mutex> guard(_mutexStates);
 
 1350         _idleRequested = 
true;
 
 1359         std::unique_lock<std::mutex> guard(_mutexStates);
 
 1361         _resumeRequested = 
true;
 
 1369     std::unique_lock<std::mutex> guard(_mutexStates);
 
 1378     _idleRequested   = 
false;
 
 1379     _resumeRequested = 
false;
 
 1385     mCurrentFrame.ComputeBoW();
 
 1389     vector<WAIKeyFrame*> vpCandidateKFs = mpKeyFrameDatabase->DetectRelocalizationCandidates(&mCurrentFrame);
 
 1391     if (vpCandidateKFs.empty())
 
 1395     const int nKFs = vpCandidateKFs.size();
 
 1398     ORBmatcher matcher(0.75, 
true);
 
 1400     vector<vector<WAIMapPoint*>> vvpMapPointMatches;
 
 1401     vvpMapPointMatches.resize(nKFs);
 
 1403     for (
int i = 0; i < nKFs; i++)
 
 1406         int          nmatches = matcher.SearchByBoW(pKF, mCurrentFrame, vvpMapPointMatches[i]);
 
 1411         for (
size_t j = 0; j < vvpMapPointMatches[i].size(); j++)
 
 1417                 const cv::KeyPoint& kp = mCurrentFrame.mvKeys[j];
 
 1418                 vP2D.push_back(kp.pt);
 
 1420                 vP3Dw.push_back(cv::Point3f(Pos.x, Pos.y, Pos.z));
 
 1428                                        unsigned int*  lastRelocFrameId,
 
 1430                                        bool           applyMinAccScoreFilter,
 
 1431                                        bool           relocWithAllKFs)
 
 1439     vector<WAIKeyFrame*> vpCandidateKFs;
 
 1440     if (relocWithAllKFs)
 
 1458     if (vpCandidateKFs.empty())
 
 1465     const int nKFs = vpCandidateKFs.size();
 
 1470     ORBmatcher matcher(0.75, 
true);
 
 1472     vector<PnPsolver*> vpPnPsolvers;
 
 1473     vpPnPsolvers.resize(nKFs);
 
 1475     vector<vector<WAIMapPoint*>> vvpMapPointMatches;
 
 1476     vvpMapPointMatches.resize(nKFs);
 
 1478     vector<bool> vbDiscarded;
 
 1479     vbDiscarded.resize(nKFs);
 
 1481     int nCandidates = 0;
 
 1483     for (
int i = 0; i < nKFs; i++)
 
 1487             vbDiscarded[i] = 
true;
 
 1490             int nmatches = matcher.SearchByBoW(pKF, currentFrame, vvpMapPointMatches[i]);
 
 1494                 vbDiscarded[i] = 
true;
 
 1499                 PnPsolver* pSolver = 
new PnPsolver(currentFrame, vvpMapPointMatches[i]);
 
 1500                 pSolver->SetRansacParameters(0.99, 10, 300, 4, 0.5, 5.991);
 
 1501                 vpPnPsolvers[i] = pSolver;
 
 1509     bool       bMatch = 
false;
 
 1510     ORBmatcher matcher2(0.9, 
true);
 
 1512     while (nCandidates > 0 && !bMatch)
 
 1514         for (
int i = 0; i < nKFs; i++)
 
 1520             vector<bool> vbInliers;
 
 1521             vector<bool> vbOutliers;
 
 1525             PnPsolver* pSolver = vpPnPsolvers[i];
 
 1526             cv::Mat    Tcw     = pSolver->iterate(5, bNoMore, vbInliers, nInliers);
 
 1531                 vbDiscarded[i] = 
true;
 
 1538                 Tcw.copyTo(currentFrame.
mTcw);
 
 1540                 set<WAIMapPoint*> sFound;
 
 1542                 const int np = vbInliers.size();
 
 1544                 for (
int j = 0; j < np; j++)
 
 1548                         currentFrame.
mvpMapPoints[j] = vvpMapPointMatches[i][j];
 
 1549                         sFound.insert(vvpMapPointMatches[i][j]);
 
 1555                 int nGood = Optimizer::PoseOptimization(¤tFrame, vbOutliers);
 
 1571                     int nadditional = matcher2.SearchByProjection(currentFrame, vpCandidateKFs[i], sFound, 10, 100);
 
 1573                     if (nadditional + nGood >= 50)
 
 1575                         nGood = Optimizer::PoseOptimization(¤tFrame, vbOutliers);
 
 1579                         if (nGood > 30 && nGood < 50)
 
 1582                             for (
int ip = 0; ip < currentFrame.
N; ip++)
 
 1585                             nadditional = matcher2.SearchByProjection(currentFrame, vpCandidateKFs[i], sFound, 3, 64);
 
 1588                             if (nGood + nadditional >= 50)
 
 1590                                 nGood = Optimizer::PoseOptimization(¤tFrame);
 
 1613         *lastRelocFrameId = currentFrame.
mnId;
 
 1620     return mCurrentFrame;
 
 1636     mCurrentFrame.ComputeBoW();
 
 1640     ORBmatcher           matcher(0.7, 
true);
 
 1641     vector<WAIMapPoint*> vpMapPointMatches;
 
 1643     int nmatches = matcher.SearchByBoW(mpReferenceKF, mCurrentFrame, vpMapPointMatches);
 
 1651     mCurrentFrame.mvpMapPoints = vpMapPointMatches;
 
 1652     mCurrentFrame.SetPose(mLastFrame.mTcw);
 
 1654     nmatches = Optimizer::PoseOptimization(&mCurrentFrame);
 
 1681     return nmatches >= 10;
 
 1703     searchLocalPoints();
 
 1706     Optimizer::PoseOptimization(&mCurrentFrame);
 
 1707     mnMatchesInliers = 0;
 
 1710     for (
int i = 0; i < mCurrentFrame.N; i++)
 
 1712         if (mCurrentFrame.mvpMapPoints[i])
 
 1714             mCurrentFrame.mvpMapPoints[i]->IncreaseFound();
 
 1715             if (!_params.onlyTracking)
 
 1717                 if (mCurrentFrame.mvpMapPoints[i]->Observations() > 0)
 
 1734     if (mCurrentFrame.mnId < mnLastRelocFrameId + mMaxFrames && mnMatchesInliers < 50)
 
 1740     if (mnMatchesInliers < 30)
 
 1752     updateLocalKeyFrames();
 
 1753     updateLocalPoints();
 
 1759     for (vector<WAIMapPoint*>::iterator vit = mCurrentFrame.mvpMapPoints.begin(), vend = mCurrentFrame.mvpMapPoints.end(); vit != vend; vit++)
 
 1780     for (vector<WAIMapPoint*>::iterator vit = mvpLocalMapPoints.begin(), vend = mvpLocalMapPoints.end(); vit != vend; vit++)
 
 1788         if (mCurrentFrame.isInFrustum(pMP, 0.5))
 
 1805         ORBmatcher matcher(0.8);
 
 1808         if (mCurrentFrame.mnId < mnLastRelocFrameId + 2)
 
 1810         matcher.SearchByProjection(mCurrentFrame, mvpLocalMapPoints, th);
 
 1817     map<WAIKeyFrame*, int> keyframeCounter;
 
 1818     for (
int i = 0; i < mCurrentFrame.N; i++)
 
 1820         if (mCurrentFrame.mvpMapPoints[i])
 
 1825                 const map<WAIKeyFrame*, size_t> observations = pMP->
GetObservations();
 
 1826                 for (map<WAIKeyFrame*, size_t>::const_iterator it = observations.begin(), itend = observations.end(); it != itend; it++)
 
 1827                     keyframeCounter[it->first]++;
 
 1831                 mCurrentFrame.mvpMapPoints[i] = NULL;
 
 1836     if (keyframeCounter.empty())
 
 1842     mvpLocalKeyFrames.clear();
 
 1843     mvpLocalKeyFrames.reserve(3 * keyframeCounter.size());
 
 1846     for (map<WAIKeyFrame*, int>::const_iterator it = keyframeCounter.begin(), itEnd = keyframeCounter.end(); it != itEnd; it++)
 
 1853         if (it->second > max)
 
 1859         mvpLocalKeyFrames.push_back(it->first);
 
 1860         pKF->mnTrackReferenceForFrame = mCurrentFrame.
mnId;
 
 1864     for (
auto itKF = mvpLocalKeyFrames.begin(); itKF != mvpLocalKeyFrames.end(); itKF++)
 
 1867         if (mvpLocalKeyFrames.size() > 80)
 
 1874         for (vector<WAIKeyFrame*>::const_iterator itNeighKF = vNeighs.begin(), itEndNeighKF = vNeighs.end(); itNeighKF != itEndNeighKF; itNeighKF++)
 
 1877             if (!pNeighKF->
isBad())
 
 1879                 if (pNeighKF->mnTrackReferenceForFrame != mCurrentFrame.
mnId)
 
 1881                     mvpLocalKeyFrames.push_back(pNeighKF);
 
 1882                     pNeighKF->mnTrackReferenceForFrame = mCurrentFrame.
mnId;
 
 1888         const set<WAIKeyFrame*> spChilds = pKF->
GetChilds();
 
 1889         for (set<WAIKeyFrame*>::const_iterator sit = spChilds.begin(), send = spChilds.end(); sit != send; sit++)
 
 1892             if (!pChildKF->
isBad())
 
 1894                 if (pChildKF->mnTrackReferenceForFrame != mCurrentFrame.
mnId)
 
 1896                     mvpLocalKeyFrames.push_back(pChildKF);
 
 1897                     pChildKF->mnTrackReferenceForFrame = mCurrentFrame.
mnId;
 
 1906             if (pParent->mnTrackReferenceForFrame != mCurrentFrame.
mnId)
 
 1908                 mvpLocalKeyFrames.push_back(pParent);
 
 1909                 pParent->mnTrackReferenceForFrame = mCurrentFrame.
mnId;
 
 1917         mpReferenceKF               = pKFmax;
 
 1918         mCurrentFrame.mpReferenceKF = mpReferenceKF;
 
 1924     mvpLocalMapPoints.clear();
 
 1926     for (vector<WAIKeyFrame*>::const_iterator itKF = mvpLocalKeyFrames.begin(), itEndKF = mvpLocalKeyFrames.end(); itKF != itEndKF; itKF++)
 
 1931         for (vector<WAIMapPoint*>::const_iterator itMP = vpMPs.begin(), itEndMP = vpMPs.end(); itMP != itEndMP; itMP++)
 
 1936             if (pMP->mnTrackReferenceForFrame == mCurrentFrame.
mnId)
 
 1940                 mvpLocalMapPoints.push_back(pMP);
 
 1941                 pMP->mnTrackReferenceForFrame = mCurrentFrame.
mnId;
 
 1961     ORBmatcher matcher(0.9, 
true);
 
 1968     mCurrentFrame.SetPose(mVelocity * mLastFrame.mTcw);
 
 1970     fill(mCurrentFrame.mvpMapPoints.begin(), mCurrentFrame.mvpMapPoints.end(), 
static_cast<WAIMapPoint*
>(NULL));
 
 1974     int nmatches = matcher.SearchByProjection(mCurrentFrame, mLastFrame, th, 
true);
 
 1979         fill(mCurrentFrame.mvpMapPoints.begin(), mCurrentFrame.mvpMapPoints.end(), 
static_cast<WAIMapPoint*
>(NULL));
 
 1980         nmatches = matcher.SearchByProjection(mCurrentFrame, mLastFrame, 2 * th, 
true);
 
 1990     Optimizer::PoseOptimization(&mCurrentFrame);
 
 1993     int nmatchesMap = 0;
 
 1994     for (
int i = 0; i < mCurrentFrame.N; i++)
 
 1996         if (mCurrentFrame.mvpMapPoints[i])
 
 1998             if (mCurrentFrame.mvpMapPoints[i]->Observations() > 0)
 
 2018     if (_params.onlyTracking)
 
 2020         mbVO = nmatchesMap < 10;
 
 2021         return nmatches > 20;
 
 2024     return nmatchesMap >= 10;
 
 2030     float maxReprojError = 10.0;
 
 2032     if (mLastFrame.mvKeys.size() < 100)
 
 2037     std::vector<uint8_t> status;
 
 2038     std::vector<float>   err;
 
 2039     cv::Size             winSize(15, 15);
 
 2041     cv::TermCriteria criteria(cv::TermCriteria::COUNT | cv::TermCriteria::EPS,
 
 2045     std::vector<cv::Point2f> keyPointCoordinatesLastFrame;
 
 2046     vector<WAIMapPoint*>     matchedMapPoints;
 
 2047     vector<cv::KeyPoint>     matchedKeyPoints;
 
 2052         matchedMapPoints = _optFlowMapPtsLastFrame;
 
 2053         matchedKeyPoints = _optFlowKeyPtsLastFrame;
 
 2054         for (
int i = 0; i < _optFlowKeyPtsLastFrame.size(); i++)
 
 2056             keyPointCoordinatesLastFrame.push_back(_optFlowKeyPtsLastFrame[i].pt);
 
 2062         for (
int i = 0; i < mLastFrame.mvpMapPoints.size(); i++)
 
 2065             if (mLastFrame.mvpMapPoints[i])
 
 2067                 keyPointCoordinatesLastFrame.push_back(mLastFrame.mvKeys[i].pt);
 
 2069                 matchedMapPoints.push_back(mLastFrame.mvpMapPoints[i]);
 
 2070                 matchedKeyPoints.push_back(mLastFrame.mvKeys[i]);
 
 2075     if (!keyPointCoordinatesLastFrame.size())
 
 2081     std::vector<cv::Point2f> pred2DPoints(keyPointCoordinatesLastFrame.size());
 
 2083     cv::calcOpticalFlowPyrLK(
 
 2085       mCurrentFrame.imgGray,        
 
 2086       keyPointCoordinatesLastFrame, 
 
 2097     std::vector<cv::Point2f> frame2DPoints;
 
 2098     std::vector<cv::Point3f> model3DPoints;
 
 2099     vector<WAIMapPoint*>     trackedMapPoints;
 
 2100     vector<cv::KeyPoint>     trackedKeyPoints;
 
 2102     mnMatchesInliers = 0;
 
 2104     for (
size_t i = 0; i < status.size(); i++)
 
 2110             frame2DPoints.push_back(pred2DPoints[i]);
 
 2111             cv::Point3f p3(matchedMapPoints[i]->GetWorldPos());
 
 2112             model3DPoints.push_back(p3);
 
 2114             matchedKeyPoints[i].pt.x = pred2DPoints[i].x;
 
 2115             matchedKeyPoints[i].pt.y = pred2DPoints[i].y;
 
 2117             trackedMapPoints.push_back(matchedMapPoints[i]);
 
 2118             trackedKeyPoints.push_back(matchedKeyPoints[i]);
 
 2120             std::lock_guard<std::mutex> guard(_nMapMatchesLock);
 
 2136     for (
int i = 0; i < trackedKeyPoints.size(); ++i)
 
 2138         int nGridPosX, nGridPosY;
 
 2140             gridOptFlow[nGridPosX][nGridPosY].push_back(i);
 
 2143     for (
int i = 0; i < mCurrentFrame.mvpMapPoints.size(); ++i)
 
 2145         if (mCurrentFrame.mvpMapPoints[i] != NULL)
 
 2147             int nGridPosX, nGridPosY;
 
 2149                 gridCurrFrame[nGridPosX][nGridPosY].push_back(i);
 
 2158             const auto& optFlowCell = gridOptFlow[i][j];
 
 2159             if (optFlowCell.size() < addThres)
 
 2161                 const std::vector<size_t>& indices = gridCurrFrame[i][j];
 
 2162                 for (
auto indexCF : indices)
 
 2164                     const cv::KeyPoint& keyPt = mCurrentFrame.mvKeys[indexCF];
 
 2165                     WAIMapPoint*        mapPt = mCurrentFrame.mvpMapPoints[indexCF];
 
 2169                         bool alreadyContained = 
false;
 
 2170                         for (
auto indexOF : optFlowCell)
 
 2172                             if (trackedMapPoints[indexOF] == mapPt)
 
 2174                                 alreadyContained = 
true;
 
 2179                         if (!alreadyContained)
 
 2182                             trackedKeyPoints.push_back(keyPt);
 
 2183                             trackedMapPoints.push_back(mapPt);
 
 2184                             frame2DPoints.push_back(keyPt.pt);
 
 2185                             model3DPoints.push_back(cv::Point3f(mapPt->
GetWorldPos()));
 
 2193     if (trackedKeyPoints.size() < matchedKeyPoints.size() * 0.75)
 
 2202     cv::Mat rvec = cv::Mat::zeros(3, 1, CV_64FC1);
 
 2203     cv::Mat tvec = cv::Mat::zeros(3, 1, CV_64FC1);
 
 2204     cv::Mat om   = mCurrentFrame.mTcw;
 
 2205     cv::Rodrigues(om.rowRange(0, 3).colRange(0, 3), rvec);
 
 2206     tvec = om.colRange(3, 4).rowRange(0, 3);
 
 2208     bool foundPose = cv::solvePnP(model3DPoints,
 
 2218         cv::Mat Tcw         = cv::Mat::eye(4, 4, CV_32F);
 
 2219         Tcw.at<
float>(0, 3) = tvec.at<
float>(0, 0);
 
 2220         Tcw.at<
float>(1, 3) = tvec.at<
float>(1, 0);
 
 2221         Tcw.at<
float>(2, 3) = tvec.at<
float>(2, 0);
 
 2223         cv::Mat Rcw = cv::Mat::zeros(3, 3, CV_32F);
 
 2224         cv::Rodrigues(rvec, Rcw);
 
 2226         Tcw.at<
float>(0, 0) = Rcw.at<
float>(0, 0);
 
 2227         Tcw.at<
float>(1, 0) = Rcw.at<
float>(1, 0);
 
 2228         Tcw.at<
float>(2, 0) = Rcw.at<
float>(2, 0);
 
 2229         Tcw.at<
float>(0, 1) = Rcw.at<
float>(0, 1);
 
 2230         Tcw.at<
float>(1, 1) = Rcw.at<
float>(1, 1);
 
 2231         Tcw.at<
float>(2, 1) = Rcw.at<
float>(2, 1);
 
 2232         Tcw.at<
float>(0, 2) = Rcw.at<
float>(0, 2);
 
 2233         Tcw.at<
float>(1, 2) = Rcw.at<
float>(1, 2);
 
 2234         Tcw.at<
float>(2, 2) = Rcw.at<
float>(2, 2);
 
 2239         std::vector<cv::Point2f> projectedPts;
 
 2240         cv::projectPoints(model3DPoints,
 
 2247         _optFlowMapPtsLastFrame.clear();
 
 2248         _optFlowKeyPtsLastFrame.clear();
 
 2249         for (
int i = 0; i < trackedMapPoints.size(); ++i)
 
 2252             float error = cv::norm(cv::Mat(projectedPts[i]), cv::Mat(frame2DPoints[i]));
 
 2253             if (error < maxReprojError)
 
 2255                 _optFlowMapPtsLastFrame.push_back(trackedMapPoints[i]);
 
 2256                 _optFlowKeyPtsLastFrame.push_back(trackedKeyPoints[i]);
 
 2270     cv::Mat Tlr = mlRelativeFramePoses.back();
 
 2287 size_t WAI::ModeOrbSlam2::getSizeOf()
 
 2291     size += 
sizeof(*this);
 
 2302     WAIKeyFrame* result = mCurrentFrame.mpReferenceKF;
 
 2310     calculateMeanReprojectionError();
 
 2312     calculatePoseDifference();
 
 2322     double reprojectionError = 0.0;
 
 2326     const cv::Mat Rcw = mCurrentFrame.GetRotationCW();
 
 2327     const cv::Mat tcw = mCurrentFrame.GetTranslationCW();
 
 2329     const float fx = mCurrentFrame.fx;
 
 2330     const float fy = mCurrentFrame.fy;
 
 2331     const float cx = mCurrentFrame.cx;
 
 2332     const float cy = mCurrentFrame.cy;
 
 2334     for (
size_t i = 0; i < mCurrentFrame.N; i++)
 
 2336         if (mCurrentFrame.mvpMapPoints[i])
 
 2338             if (mCurrentFrame.mvpMapPoints[i]->Observations() > 0)
 
 2341                 cv::Mat Pw = mCurrentFrame.mvpMapPoints[i]->GetWorldPos();
 
 2343                 const cv::Mat Pc  = Rcw * Pw + tcw;
 
 2344                 const float&  PcX = Pc.at<
float>(0);
 
 2345                 const float&  PcY = Pc.at<
float>(1);
 
 2346                 const float&  PcZ = Pc.at<
float>(2);
 
 2353                 const float invz = 1.0f / PcZ;
 
 2354                 const float u    = fx * PcX * invz + cx;
 
 2355                 const float v    = fy * PcY * invz + cy;
 
 2357                 cv::Point2f ptProj(u, v);
 
 2359                 const auto& ptImg = mCurrentFrame.mvKeysUn[i].pt;
 
 2366                 reprojectionError += cv::norm(cv::Mat(ptImg), cv::Mat(ptProj));
 
 2373         std::lock_guard<std::mutex> guard(_meanProjErrorLock);
 
 2376             _meanReprojectionError = reprojectionError / n;
 
 2380             _meanReprojectionError = -1;
 
 2387     std::lock_guard<std::mutex> guard(_poseDiffLock);
 
 2389     if (!mLastFrame.mTcw.empty() && !mCurrentFrame.mTcw.empty())
 
 2390         _poseDifference = norm(mLastFrame.mTcw - mCurrentFrame.mTcw);
 
 2392         _poseDifference = -1.0;
 
 2398     for (
size_t i = 0; i < mCurrentFrame.N; i++)
 
 2402         const auto& pt = mCurrentFrame.mvKeys[i].pt;
 
 2403         cv::rectangle(image,
 
 2404                       cv::Rect(pt.x - 3, pt.y - 3, 7, 7),
 
 2405                       cv::Scalar(0, 0, 255));
 
 2414         for (
size_t i = 0; i < _optFlowKeyPtsLastFrame.size(); i++)
 
 2417             const auto& pt = _optFlowKeyPtsLastFrame[i].pt;
 
 2418             cv::rectangle(image,
 
 2419                           cv::Rect(pt.x - 3, pt.y - 3, 7, 7),
 
 2420                           cv::Scalar(0, 255, 0));
 
 2425         for (
size_t i = 0; i < mCurrentFrame.N; i++)
 
 2427             if (mCurrentFrame.mvpMapPoints[i])
 
 2429                 if (mCurrentFrame.mvpMapPoints[i]->Observations() > 0)
 
 2432                     const auto& pt = mCurrentFrame.mvKeys[i].pt;
 
 2433                     cv::rectangle(image,
 
 2434                                   cv::Rect(pt.x - 3, pt.y - 3, 7, 7),
 
 2435                                   cv::Scalar(0, 255, 0));
 
 2444                                              cv::Mat&     homography,
 
 2447     bool result = 
false;
 
 2449     ORBmatcher matcher(0.9, 
true);
 
 2451     std::vector<int> markerMatchesToCurrentFrame;
 
 2452     int              nmatches = matcher.SearchForMarkerMap(markerFrame, *kfCand, markerMatchesToCurrentFrame);
 
 2454     if (nmatches > minMatches)
 
 2456         std::vector<cv::Point2f> markerPoints;
 
 2457         std::vector<cv::Point2f> framePoints;
 
 2459         for (
int j = 0; j < markerMatchesToCurrentFrame.size(); j++)
 
 2461             if (markerMatchesToCurrentFrame[j] >= 0)
 
 2463                 markerPoints.push_back(markerFrame.
mvKeysUn[j].pt);
 
 2464                 framePoints.push_back(kfCand->
mvKeysUn[markerMatchesToCurrentFrame[j]].pt);
 
 2468         homography = cv::findHomography(markerPoints,
 
 2472         if (!homography.empty())
 
 2474             homography.convertTo(homography, CV_32F);
 
 2484     cv::Mat markerImgGray = cv::imread(markerFile, cv::IMREAD_GRAYSCALE);
 
 2486     float fyCam = _cameraMat.at<
float>(1, 1);
 
 2487     float cyCam = _cameraMat.at<
float>(1, 2);
 
 2488     float fov   = 2.0f * atan2(cyCam, fyCam) * 180.0f / M_PI;
 
 2490     float cx = (float)markerImgGray.cols * 0.5f;
 
 2491     float cy = (
float)markerImgGray.rows * 0.5f;
 
 2492     float fy = cy / tanf(fov * 0.5f * M_PI / 180.0);
 
 2496     cv::Mat markerCameraMat     = (cv::Mat_<float>(3, 3) << fx, 0, cx, 0, fy, cy, 0, 0, 1);
 
 2497     cv::Mat markerDistortionMat = cv::Mat::zeros(4, 1, CV_32F);
 
 2499     WAIFrame result = 
WAIFrame(markerImgGray, 0.0f, markerExtractor, markerCameraMat, markerDistortionMat, mpVocabulary, 
true);
 
 2500     result          = 
WAIFrame(markerImgGray, 0.0f, markerExtractor, markerCameraMat, markerDistortionMat, mpVocabulary, 
true);
 
 2501     result          = 
WAIFrame(markerImgGray, 0.0f, markerExtractor, markerCameraMat, markerDistortionMat, mpVocabulary, 
true);
 
 2506                                                  cv::Mat&    nodeTransform,
 
 2507                                                  float       markerWidthInM)
 
 2512     WAIFrame markerFrame = createMarkerFrame(markerFile, _markerExtractor);
 
 2515     std::vector<WAIKeyFrame*> kfs = _map->GetAllKeyFrames();
 
 2520     cv::Mat ul = cv::Mat(cv::Point3f(0, 0, 1));
 
 2521     cv::Mat ur = cv::Mat(cv::Point3f(markerFrame.
imgGray.cols, 0, 1));
 
 2522     cv::Mat ll = cv::Mat(cv::Point3f(0, markerFrame.
imgGray.rows, 1));
 
 2523     cv::Mat lr = cv::Mat(cv::Point3f(markerFrame.
imgGray.cols, markerFrame.
imgGray.rows, 1));
 
 2525     cv::Mat ulKf1, urKf1, llKf1, lrKf1, ulKf2, urKf2, llKf2, lrKf2;
 
 2526     cv::Mat ul3D, ur3D, ll3D, lr3D;
 
 2529     for (
int i1 = 0; i1 < kfs.size() - 1; i1++)
 
 2533         if (kfCand1->
isBad()) 
continue;
 
 2536         cv::Mat homography1;
 
 2537         if (findMarkerHomography(markerFrame, kfCand1, homography1, 50))
 
 2542             ulKf1 = homography1 * ul;
 
 2543             ulKf1 /= ulKf1.at<
float>(2, 0);
 
 2544             urKf1 = homography1 * ur;
 
 2545             urKf1 /= urKf1.at<
float>(2, 0);
 
 2546             llKf1 = homography1 * ll;
 
 2547             llKf1 /= llKf1.at<
float>(2, 0);
 
 2548             lrKf1 = homography1 * lr;
 
 2549             lrKf1 /= lrKf1.at<
float>(2, 0);
 
 2551             for (
int i2 = i1 + 1; i2 < kfs.size(); i2++)
 
 2555                 if (kfCand2->
isBad()) 
continue;
 
 2557                 cv::Mat homography2;
 
 2558                 if (findMarkerHomography(markerFrame, kfCand2, homography2, 50))
 
 2563                     ulKf2 = homography2 * ul;
 
 2564                     ulKf2 /= ulKf2.at<
float>(2, 0);
 
 2565                     urKf2 = homography2 * ur;
 
 2566                     urKf2 /= urKf2.at<
float>(2, 0);
 
 2567                     llKf2 = homography2 * ll;
 
 2568                     llKf2 /= llKf2.at<
float>(2, 0);
 
 2569                     lrKf2 = homography2 * lr;
 
 2570                     lrKf2 /= lrKf2.at<
float>(2, 0);
 
 2574                     cv::Mat Rwc1 = Rcw1.t();
 
 2576                     cv::Mat Tcw1(3, 4, CV_32F);
 
 2577                     Rcw1.copyTo(Tcw1.colRange(0, 3));
 
 2578                     tcw1.copyTo(Tcw1.col(3));
 
 2580                     const float& fx1    = kfCand1->
fx;
 
 2581                     const float& fy1    = kfCand1->
fy;
 
 2582                     const float& cx1    = kfCand1->
cx;
 
 2583                     const float& cy1    = kfCand1->
cy;
 
 2584                     const float& invfx1 = kfCand1->
invfx;
 
 2585                     const float& invfy1 = kfCand1->
invfy;
 
 2588                     cv::Mat Rwc2 = Rcw2.t();
 
 2590                     cv::Mat Tcw2(3, 4, CV_32F);
 
 2591                     Rcw2.copyTo(Tcw2.colRange(0, 3));
 
 2592                     tcw2.copyTo(Tcw2.col(3));
 
 2594                     const float& fx2    = kfCand2->
fx;
 
 2595                     const float& fy2    = kfCand2->
fy;
 
 2596                     const float& cx2    = kfCand2->
cx;
 
 2597                     const float& cy2    = kfCand2->
cy;
 
 2598                     const float& invfx2 = kfCand2->
invfx;
 
 2599                     const float& invfy2 = kfCand2->
invfy;
 
 2602                         cv::Mat ul1 = (cv::Mat_<float>(3, 1) << (ulKf1.at<
float>(0, 0) - cx1) * invfx1, (ulKf1.at<
float>(1, 0) - cy1) * invfy1, 1.0);
 
 2603                         cv::Mat ul2 = (cv::Mat_<float>(3, 1) << (ulKf2.at<
float>(0, 0) - cx2) * invfx2, (ulKf2.at<
float>(1, 0) - cy2) * invfy2, 1.0);
 
 2606                         cv::Mat A(4, 4, CV_32F);
 
 2607                         A.row(0) = ul1.at<
float>(0) * Tcw1.row(2) - Tcw1.row(0);
 
 2608                         A.row(1) = ul1.at<
float>(1) * Tcw1.row(2) - Tcw1.row(1);
 
 2609                         A.row(2) = ul2.at<
float>(0) * Tcw2.row(2) - Tcw2.row(0);
 
 2610                         A.row(3) = ul2.at<
float>(1) * Tcw2.row(2) - Tcw2.row(1);
 
 2613                         cv::SVD::compute(A, w, u, vt, cv::SVD::MODIFY_A | cv::SVD::FULL_UV);
 
 2615                         ul3D = vt.row(3).t();
 
 2617                         if (ul3D.at<
float>(3) != 0)
 
 2620                             ul3D = ul3D.rowRange(0, 3) / ul3D.at<
float>(3);
 
 2625                         cv::Mat ur1 = (cv::Mat_<float>(3, 1) << (urKf1.at<
float>(0, 0) - cx1) * invfx1, (urKf1.at<
float>(1, 0) - cy1) * invfy1, 1.0);
 
 2626                         cv::Mat ur2 = (cv::Mat_<float>(3, 1) << (urKf2.at<
float>(0, 0) - cx2) * invfx2, (urKf2.at<
float>(1, 0) - cy2) * invfy2, 1.0);
 
 2629                         cv::Mat A(4, 4, CV_32F);
 
 2630                         A.row(0) = ur1.at<
float>(0) * Tcw1.row(2) - Tcw1.row(0);
 
 2631                         A.row(1) = ur1.at<
float>(1) * Tcw1.row(2) - Tcw1.row(1);
 
 2632                         A.row(2) = ur2.at<
float>(0) * Tcw2.row(2) - Tcw2.row(0);
 
 2633                         A.row(3) = ur2.at<
float>(1) * Tcw2.row(2) - Tcw2.row(1);
 
 2636                         cv::SVD::compute(A, w, u, vt, cv::SVD::MODIFY_A | cv::SVD::FULL_UV);
 
 2638                         ur3D = vt.row(3).t();
 
 2640                         if (ur3D.at<
float>(3) != 0)
 
 2643                             ur3D = ur3D.rowRange(0, 3) / ur3D.at<
float>(3);
 
 2648                         cv::Mat ll1 = (cv::Mat_<float>(3, 1) << (llKf1.at<
float>(0, 0) - cx1) * invfx1, (llKf1.at<
float>(1, 0) - cy1) * invfy1, 1.0);
 
 2649                         cv::Mat ll2 = (cv::Mat_<float>(3, 1) << (llKf2.at<
float>(0, 0) - cx2) * invfx2, (llKf2.at<
float>(1, 0) - cy2) * invfy2, 1.0);
 
 2652                         cv::Mat A(4, 4, CV_32F);
 
 2653                         A.row(0) = ll1.at<
float>(0) * Tcw1.row(2) - Tcw1.row(0);
 
 2654                         A.row(1) = ll1.at<
float>(1) * Tcw1.row(2) - Tcw1.row(1);
 
 2655                         A.row(2) = ll2.at<
float>(0) * Tcw2.row(2) - Tcw2.row(0);
 
 2656                         A.row(3) = ll2.at<
float>(1) * Tcw2.row(2) - Tcw2.row(1);
 
 2659                         cv::SVD::compute(A, w, u, vt, cv::SVD::MODIFY_A | cv::SVD::FULL_UV);
 
 2661                         ll3D = vt.row(3).t();
 
 2663                         if (ll3D.at<
float>(3) != 0)
 
 2666                             ll3D = ll3D.rowRange(0, 3) / ll3D.at<
float>(3);
 
 2671                         cv::Mat lr1 = (cv::Mat_<float>(3, 1) << (lrKf1.at<
float>(0, 0) - cx1) * invfx1, (lrKf1.at<
float>(1, 0) - cy1) * invfy1, 1.0);
 
 2672                         cv::Mat lr2 = (cv::Mat_<float>(3, 1) << (lrKf2.at<
float>(0, 0) - cx2) * invfx2, (lrKf2.at<
float>(1, 0) - cy2) * invfy2, 1.0);
 
 2675                         cv::Mat A(4, 4, CV_32F);
 
 2676                         A.row(0) = lr1.at<
float>(0) * Tcw1.row(2) - Tcw1.row(0);
 
 2677                         A.row(1) = lr1.at<
float>(1) * Tcw1.row(2) - Tcw1.row(1);
 
 2678                         A.row(2) = lr2.at<
float>(0) * Tcw2.row(2) - Tcw2.row(0);
 
 2679                         A.row(3) = lr2.at<
float>(1) * Tcw2.row(2) - Tcw2.row(1);
 
 2682                         cv::SVD::compute(A, w, u, vt, cv::SVD::MODIFY_A | cv::SVD::FULL_UV);
 
 2684                         lr3D = vt.row(3).t();
 
 2686                         if (lr3D.at<
float>(3) != 0)
 
 2689                             lr3D = lr3D.rowRange(0, 3) / lr3D.at<
float>(3);
 
 2699                     cv::Vec3f vn = vAB.cross(vAC);
 
 2702                     cv::Mat   AD  = lr3D - ul3D;
 
 2705                     float d = cv::norm(vn.dot(vAD)) / cv::norm(vn);
 
 2708                         matchedKf1 = kfCand1;
 
 2709                         matchedKf2 = kfCand2;
 
 2717         if (matchedKf2) 
break;
 
 2720     if (!matchedKf1 || !matchedKf2)
 
 2726     std::vector<WAIMapPoint*> mapPoints = _map->GetAllMapPoints();
 
 2728     cv::Mat system = cv::Mat::zeros(3, 3, CV_32F);
 
 2729     AC.copyTo(system.rowRange(0, 3).col(0));
 
 2730     AB.copyTo(system.rowRange(0, 3).col(1));
 
 2731     n.copyTo(system.rowRange(0, 3).col(2));
 
 2733     cv::Mat systemInv = system.inv();
 
 2735     for (
int i = 0; i < mapPoints.size(); i++)
 
 2739         if (mp->
isBad()) 
continue;
 
 2741         cv::Mat sol = systemInv * (mp->
GetWorldPos() - ul3D);
 
 2743         if (sol.at<
float>(0, 0) < 0 || sol.at<
float>(0, 0) > 1 ||
 
 2744             sol.at<
float>(1, 0) < 0 || sol.at<
float>(1, 0) > 1 ||
 
 2745             sol.at<
float>(2, 0) < -0.1f || sol.at<
float>(2, 0) > 0.1f)
 
 2751     for (
int i = 0; i < kfs.size(); i++)
 
 2755         if (kf->
mnId == 0 || kf->
isBad()) 
continue;
 
 2760         for (
int j = 0; j < mps.size(); j++)
 
 2764             if (!mp || mp->
isBad()) 
continue;
 
 2778     float cullRedundantPerc = 0.95f; 
 
 2779     for (
int i = 0; i < kfs.size(); i++)
 
 2785         for (vector<WAIKeyFrame*>::iterator vit = vpLocalKeyFrames.begin(), vend = vpLocalKeyFrames.end(); vit != vend; vit++)
 
 2797             const int thObs                  = 3;
 
 2798             int       nRedundantObservations = 0;
 
 2800             for (
size_t i = 0, iend = vpMapPoints.size(); i < iend; i++)
 
 2810                             const int&                           scaleLevel   = pKF->
mvKeysUn[i].octave;
 
 2811                             const std::map<WAIKeyFrame*, size_t> observations = pMP->
GetObservations();
 
 2813                             for (std::map<WAIKeyFrame*, size_t>::const_iterator mit = observations.begin(), mend = observations.end(); mit != mend; mit++)
 
 2818                                 const int& scaleLeveli = pKFi->
mvKeysUn[mit->second].octave;
 
 2820                                 if (scaleLeveli <= scaleLevel + 1)
 
 2831                                 nRedundantObservations++;
 
 2838             if (nMPs == 0 || nRedundantObservations > cullRedundantPerc * nMPs)
 
 2845     cv::Mat systemNorm               = cv::Mat::zeros(3, 3, CV_32F);
 
 2846     systemNorm.rowRange(0, 3).col(0) = system.rowRange(0, 3).col(1) / cv::norm(AB);
 
 2847     systemNorm.rowRange(0, 3).col(1) = system.rowRange(0, 3).col(0) / cv::norm(AC);
 
 2848     systemNorm.rowRange(0, 3).col(2) = system.rowRange(0, 3).col(2) / cv::norm(n);
 
 2850     cv::Mat systemNormInv = systemNorm.inv();
 
 2852     nodeTransform   = cv::Mat::eye(4, 4, CV_32F);
 
 2853     cv::Mat ul3Dinv = -systemNormInv * ul3D;
 
 2854     ul3Dinv.copyTo(nodeTransform.rowRange(0, 3).col(3));
 
 2855     systemNormInv.copyTo(nodeTransform.rowRange(0, 3).colRange(0, 3));
 
 2857     cv::Mat scaleMat         = cv::Mat::eye(4, 4, CV_32F);
 
 2858     float   markerWidthInRef = cv::norm(ul3D - ur3D);
 
 2859     float   scaleFactor      = markerWidthInM / markerWidthInRef;
 
 2860     scaleMat.at<
float>(0, 0) = scaleFactor;
 
 2861     scaleMat.at<
float>(1, 1) = scaleFactor;
 
 2862     scaleMat.at<
float>(2, 2) = scaleFactor;
 
 2864     nodeTransform = scaleMat * nodeTransform;
 
 2897     int result = mCurrentFrame.N;
 
#define AVERAGE_TIMING_STOP(name)
 
#define AVERAGE_TIMING_START(name)
 
#define OPTFLOW_GRID_COLS
 
#define OPTFLOW_GRID_ROWS
 
std::string getPrintableState()
 
ORB_SLAM2::ORBVocabulary * mpVocabulary
 
std::vector< WAIMapPoint * > getMatchedMapPoints()
 
void track3DPts(cv::Mat &imageGray, cv::Mat &imageRGB)
 
void setTrackOptFlow(bool flag)
 
int getMapPointMatchesCount()
 
bool doMarkerMapPreprocessing(std::string markerFile, cv::Mat &nodeTransform, float markerWidthInM)
 
WAIFrame createMarkerFrame(std::string markerFile, KPextractor *markerExtractor)
 
std::vector< WAIMapPoint * > getLocalMapPoints()
 
std::string getPrintableType()
 
static bool relocalization(WAIFrame ¤tFrame, WAIKeyFrameDB *keyFrameDB, unsigned int *lastRelocFrameId, WAIMap &waiMap, bool applyMinAccScoreFilter=true, bool relocWithAllKFs=false)
 
std::vector< WAIMapPoint * > getMapPoints()
 
WAIKeyFrameDB * mpKeyFrameDatabase
 
void checkReplacedInLastFrame()
 
void calculateMeanReprojectionError()
 
void decorate(cv::Mat &image)
 
bool update(cv::Mat &imageGray, cv::Mat &imageRGB)
 
ORB_SLAM2::KPextractor * _markerExtractor
 
ModeOrbSlam2(ORB_SLAM2::KPextractor *kpExtractor, ORB_SLAM2::KPextractor *kpIniExtractor, cv::Mat cameraMat, cv::Mat distortionMat, const Params ¶ms, std::string orbVocFile, bool applyMinAccScoreFilter=false)
 
std::thread * mptLoopClosing
 
bool findMarkerHomography(WAIFrame &markerFrame, WAIKeyFrame *kfCand, cv::Mat &homography, int minMatches)
 
void calculatePoseDifference()
 
void decorateVideoWithKeyPointMatches(cv::Mat &image)
 
std::pair< std::vector< cv::Vec3f >, std::vector< cv::Vec2f > > getMatchedCorrespondances()
 
bool trackWithMotionModel()
 
void setVocabulary(std::string orbVocFile)
 
std::vector< WAIKeyFrame * > getKeyFrames()
 
WAIKeyFrame * currentKeyFrame()
 
void decorateVideoWithKeyPoints(cv::Mat &image)
 
void initialize(cv::Mat &imageGray, cv::Mat &imageRGB)
 
int getKeyFramesInLoopCloseQueueCount()
 
std::pair< std::vector< cv::Vec3f >, std::vector< cv::Vec2f > > getCorrespondances()
 
std::thread * mptLocalMapping
 
WAIFrame getCurrentFrame()
 
bool getPose(cv::Mat *pose)
 
ORB_SLAM2::LocalMapping * mpLocalMapper
 
ORB_SLAM2::LoopClosing * mpLoopCloser
 
void findMatches(std::vector< cv::Point2f > &vP2D, std::vector< cv::Point3f > &vP3Dw)
 
void updateLocalKeyFrames()
 
bool createInitialMapMonocular(int mapPointsNeeded)
 
float getMeanReprojectionError()
 
bool trackReferenceKeyFrame()
 
bool posInGrid(const cv::KeyPoint &kp, int &posX, int &posY, int minX, int minY)
 
std::string getLoopCloseStatus()
 
std::vector< WAIMapPoint * > getMarkerCornerMapPoints()
 
std::vector< WAIMapPoint * > mvpMapPoints
 
static long unsigned int nNextId
 
std::vector< cv::KeyPoint > mvKeysUn
 
static bool mbInitialComputations
 
AR Keyframe database class.
 
std::vector< WAIKeyFrame * > DetectRelocalizationCandidates(WAIFrame *F, float minCommonWordFactor, bool applyMinAccScoreFilter=false)
 
float ComputeSceneMedianDepth(const int q)
 
void SetPose(const cv::Mat &Tcw)
 
std::vector< WAIKeyFrame * > GetBestCovisibilityKeyFrames(const int &N)
 
void AddMapPoint(WAIMapPoint *pMP, size_t idx)
 
WAIKeyFrame * GetParent()
 
std::set< WAIKeyFrame * > GetChilds()
 
const std::vector< cv::KeyPoint > mvKeysUn
 
void UpdateConnections(std::map< WAIKeyFrame *, int > KFcounter, bool buildSpanningTree)
 
std::vector< WAIKeyFrame * > GetVectorCovisibleKeyFrames()
 
std::vector< WAIMapPoint * > GetMapPointMatches()
 
void ComputeBoW(WAIOrbVocabulary *vocabulary)
 
static long unsigned int nNextId
 
long unsigned int KeyFramesInMap()
 
std::vector< WAIKeyFrame * > GetAllKeyFrames()
 
void AddObservation(WAIKeyFrame *pKF, size_t idx)
 
static long unsigned int nNextId
 
std::map< WAIKeyFrame *, size_t > GetObservations()
 
void UpdateNormalAndDepth()
 
long unsigned int mnLastFrameSeen
 
void IncreaseVisible(int n=1)
 
void ComputeDistinctiveDescriptors()
 
void SetWorldPos(const cv::Mat &Pos)
 
WAIMapPoint * GetReplaced()
 
std::vector< char > & get(std::string path)
 
void log(const char *tag, const char *format,...)
logs a formatted string platform independently
 
@ TrackingState_Initializing
 
@ TrackingState_TrackingOK
 
@ TrackingState_TrackingLost