| 226 | } |
| 227 | |
| 228 | void KeyFrameDatabase::DetectCandidates(KeyFrame* pKF, float minScore,vector<KeyFrame*>& vpLoopCand, vector<KeyFrame*>& vpMergeCand) |
| 229 | { |
| 230 | set<KeyFrame*> spConnectedKeyFrames = pKF->GetConnectedKeyFrames(); |
| 231 | list<KeyFrame*> lKFsSharingWordsLoop,lKFsSharingWordsMerge; |
| 232 | |
| 233 | // Search all keyframes that share a word with current keyframes |
| 234 | // Discard keyframes connected to the query keyframe |
| 235 | { |
| 236 | unique_lock<mutex> lock(mMutex); |
| 237 | |
| 238 | for(DBoW2::BowVector::const_iterator vit=pKF->mBowVec.begin(), vend=pKF->mBowVec.end(); vit != vend; vit++) |
| 239 | { |
| 240 | list<KeyFrame*> &lKFs = mvInvertedFile[vit->first]; |
| 241 | |
| 242 | for(list<KeyFrame*>::iterator lit=lKFs.begin(), lend= lKFs.end(); lit!=lend; lit++) |
| 243 | { |
| 244 | KeyFrame* pKFi=*lit; |
| 245 | if(pKFi->GetMap()==pKF->GetMap()) // For consider a loop candidate it a candidate it must be in the same map |
| 246 | { |
| 247 | if(pKFi->mnLoopQuery!=pKF->mnId) |
| 248 | { |
| 249 | pKFi->mnLoopWords=0; |
| 250 | if(!spConnectedKeyFrames.count(pKFi)) |
| 251 | { |
| 252 | pKFi->mnLoopQuery=pKF->mnId; |
| 253 | lKFsSharingWordsLoop.push_back(pKFi); |
| 254 | } |
| 255 | } |
| 256 | pKFi->mnLoopWords++; |
| 257 | } |
| 258 | else if(!pKFi->GetMap()->IsBad()) |
| 259 | { |
| 260 | if(pKFi->mnMergeQuery!=pKF->mnId) |
| 261 | { |
| 262 | pKFi->mnMergeWords=0; |
| 263 | if(!spConnectedKeyFrames.count(pKFi)) |
| 264 | { |
| 265 | pKFi->mnMergeQuery=pKF->mnId; |
| 266 | lKFsSharingWordsMerge.push_back(pKFi); |
| 267 | } |
| 268 | } |
| 269 | pKFi->mnMergeWords++; |
| 270 | } |
| 271 | } |
| 272 | } |
| 273 | } |
| 274 | |
| 275 | if(lKFsSharingWordsLoop.empty() && lKFsSharingWordsMerge.empty()) |
| 276 | return; |
| 277 | |
| 278 | if(!lKFsSharingWordsLoop.empty()) |
| 279 | { |
| 280 | list<pair<float,KeyFrame*> > lScoreAndMatch; |
| 281 | |
| 282 | // Only compare against those keyframes that share enough words |
| 283 | int maxCommonWords=0; |
| 284 | for(list<KeyFrame*>::iterator lit=lKFsSharingWordsLoop.begin(), lend= lKFsSharingWordsLoop.end(); lit!=lend; lit++) |
| 285 | { |
nothing calls this directly
no test coverage detected