| 98 | } |
| 99 | |
| 100 | vector<KeyFrame*> KeyFrameDatabase::DetectLoopCandidates(KeyFrame* pKF, float minScore) |
| 101 | { |
| 102 | set<KeyFrame*> spConnectedKeyFrames = pKF->GetConnectedKeyFrames(); |
| 103 | list<KeyFrame*> lKFsSharingWords; |
| 104 | |
| 105 | // Search all keyframes that share a word with current keyframes |
| 106 | // Discard keyframes connected to the query keyframe |
| 107 | { |
| 108 | unique_lock<mutex> lock(mMutex); |
| 109 | |
| 110 | for(DBoW2::BowVector::const_iterator vit=pKF->mBowVec.begin(), vend=pKF->mBowVec.end(); vit != vend; vit++) |
| 111 | { |
| 112 | list<KeyFrame*> &lKFs = mvInvertedFile[vit->first]; |
| 113 | |
| 114 | for(list<KeyFrame*>::iterator lit=lKFs.begin(), lend= lKFs.end(); lit!=lend; lit++) |
| 115 | { |
| 116 | KeyFrame* pKFi=*lit; |
| 117 | if(pKFi->GetMap()==pKF->GetMap()) // For consider a loop candidate it a candidate it must be in the same map |
| 118 | { |
| 119 | if(pKFi->mnLoopQuery!=pKF->mnId) |
| 120 | { |
| 121 | pKFi->mnLoopWords=0; |
| 122 | if(!spConnectedKeyFrames.count(pKFi)) |
| 123 | { |
| 124 | pKFi->mnLoopQuery=pKF->mnId; |
| 125 | lKFsSharingWords.push_back(pKFi); |
| 126 | } |
| 127 | } |
| 128 | pKFi->mnLoopWords++; |
| 129 | } |
| 130 | |
| 131 | |
| 132 | } |
| 133 | } |
| 134 | } |
| 135 | |
| 136 | if(lKFsSharingWords.empty()) |
| 137 | return vector<KeyFrame*>(); |
| 138 | |
| 139 | list<pair<float,KeyFrame*> > lScoreAndMatch; |
| 140 | |
| 141 | // Only compare against those keyframes that share enough words |
| 142 | int maxCommonWords=0; |
| 143 | for(list<KeyFrame*>::iterator lit=lKFsSharingWords.begin(), lend= lKFsSharingWords.end(); lit!=lend; lit++) |
| 144 | { |
| 145 | if((*lit)->mnLoopWords>maxCommonWords) |
| 146 | maxCommonWords=(*lit)->mnLoopWords; |
| 147 | } |
| 148 | |
| 149 | int minCommonWords = maxCommonWords*0.8f; |
| 150 | |
| 151 | int nscores=0; |
| 152 | |
| 153 | // Compute similarity score. Retain the matches whose score is higher than minScore |
| 154 | for(list<KeyFrame*>::iterator lit=lKFsSharingWords.begin(), lend= lKFsSharingWords.end(); lit!=lend; lit++) |
| 155 | { |
| 156 | KeyFrame* pKFi = *lit; |
| 157 |
nothing calls this directly
no test coverage detected