42 std::unique_lock<std::mutex> lock(
mMutex);
45 std::cout <<
"kf data empty" << std::endl;
56 std::unique_lock<std::mutex> lock(
mMutex);
64 for (std::list<WAIKeyFrame*>::iterator lit = lKFs.begin(), lend = lKFs.end(); lit != lend; lit++)
88 std::list<WAIKeyFrame*> lKFsSharingWords;
93 std::unique_lock<std::mutex> lock(
mMutex);
99 for (std::list<WAIKeyFrame*>::iterator lit = lKFs.begin(), lend = lKFs.end(); lit != lend; lit++)
105 if (!spConnectedKeyFrames.count(pKFi))
108 lKFsSharingWords.push_back(pKFi);
116 if (lKFsSharingWords.empty())
119 return std::vector<WAIKeyFrame*>();
122 std::list<std::pair<float, WAIKeyFrame*>> lScoreAndMatch;
125 int maxCommonWords = 0;
126 for (std::list<WAIKeyFrame*>::iterator lit = lKFsSharingWords.begin(), lend = lKFsSharingWords.end(); lit != lend; lit++)
128 if ((*lit)->mnLoopWords > maxCommonWords)
129 maxCommonWords = (*lit)->mnLoopWords;
132 int minCommonWords = (int)(maxCommonWords * minCommonWordFactor);
135 for (std::list<WAIKeyFrame*>::iterator lit = lKFsSharingWords.begin(), lend = lKFsSharingWords.end(); lit != lend; lit++)
145 lScoreAndMatch.push_back(std::make_pair(si, pKFi));
149 if (lScoreAndMatch.empty())
152 return std::vector<WAIKeyFrame*>();
155 std::list<std::pair<float, WAIKeyFrame*>> lAccScoreAndMatch;
156 float bestAccScore = minScore;
159 for (std::list<std::pair<float, WAIKeyFrame*>>::iterator it = lScoreAndMatch.begin(), itend = lScoreAndMatch.end(); it != itend; it++)
164 float bestScore = it->first;
165 float accScore = it->first;
167 for (std::vector<WAIKeyFrame*>::iterator vit = vpNeighs.begin(), vend = vpNeighs.end(); vit != vend; vit++)
181 lAccScoreAndMatch.push_back(std::make_pair(accScore, pBestKF));
182 if (accScore > bestAccScore)
183 bestAccScore = accScore;
187 float minScoreToRetain = 0.75f * bestAccScore;
189 std::set<WAIKeyFrame*> spAlreadyAddedKF;
190 std::vector<WAIKeyFrame*> vpLoopCandidates;
191 vpLoopCandidates.reserve(lAccScoreAndMatch.size());
193 for (std::list<std::pair<float, WAIKeyFrame*>>::iterator it = lAccScoreAndMatch.begin(), itend = lAccScoreAndMatch.end(); it != itend; it++)
195 if (it->first > minScoreToRetain)
198 if (!spAlreadyAddedKF.count(pKFi))
200 vpLoopCandidates.push_back(pKFi);
201 spAlreadyAddedKF.insert(pKFi);
207 return vpLoopCandidates;
213 std::list<WAIKeyFrame*> lKFsSharingWords;
217 std::unique_lock<std::mutex> lock(
mMutex);
223 std::stringstream ss;
224 ss <<
"WAIKeyFrameDB::DetectRelocalizationCandidates: word index bigger than inverted file. word: " << vit->first <<
" val: " << vit->second;
225 throw std::runtime_error(ss.str());
230 for (std::list<WAIKeyFrame*>::iterator lit = lKFs.begin(), lend = lKFs.end(); lit != lend; lit++)
241 lKFsSharingWords.push_back(pKFi);
247 if (lKFsSharingWords.empty())
248 return std::vector<WAIKeyFrame*>();
250 std::vector<WAIKeyFrame*> kfs;
251 for (std::list<WAIKeyFrame*>::iterator lit = lKFsSharingWords.begin(), lend = lKFsSharingWords.end(); lit != lend; lit++)
260 std::list<WAIKeyFrame*> lKFsSharingWords;
264 std::unique_lock<std::mutex> lock(
mMutex);
270 std::stringstream ss;
271 ss <<
"WAIKeyFrameDB::DetectRelocalizationCandidates: word index bigger than inverted file. word: " << vit->first <<
" val: " << vit->second;
272 throw std::runtime_error(ss.str());
277 for (std::list<WAIKeyFrame*>::iterator lit = lKFs.begin(), lend = lKFs.end(); lit != lend; lit++)
288 lKFsSharingWords.push_back(pKFi);
294 if (lKFsSharingWords.empty())
295 return std::vector<WAIKeyFrame*>();
298 int maxCommonWords = 0;
299 for (std::list<WAIKeyFrame*>::iterator lit = lKFsSharingWords.begin(), lend = lKFsSharingWords.end(); lit != lend; lit++)
301 if ((*lit)->mnRelocWords > maxCommonWords)
302 maxCommonWords = (*lit)->mnRelocWords;
305 int minCommonWords = (int)(maxCommonWords * minCommonWordFactor);
307 if (!applyMinAccScoreFilter)
309 std::vector<WAIKeyFrame*> vpRelocCandidates;
312 for (std::list<WAIKeyFrame*>::iterator lit = lKFsSharingWords.begin(), lend = lKFsSharingWords.end(); lit != lend; lit++)
318 vpRelocCandidates.push_back(pKFi);
322 return vpRelocCandidates;
329 std::list<std::pair<float, WAIKeyFrame*>> lScoreAndMatch;
332 for (std::list<WAIKeyFrame*>::iterator lit = lKFsSharingWords.begin(), lend = lKFsSharingWords.end(); lit != lend; lit++)
341 lScoreAndMatch.push_back(std::make_pair(si, pKFi));
345 if (lScoreAndMatch.empty())
346 return std::vector<WAIKeyFrame*>();
348 std::list<std::pair<float, WAIKeyFrame*>> lAccScoreAndMatch;
349 float bestAccScore = 0;
352 for (std::list<std::pair<float, WAIKeyFrame*>>::iterator it = lScoreAndMatch.begin(), itend = lScoreAndMatch.end(); it != itend; it++)
357 float bestScore = it->first;
358 float accScore = bestScore;
360 for (std::vector<WAIKeyFrame*>::iterator vit = vpNeighs.begin(), vend = vpNeighs.end(); vit != vend; vit++)
376 lAccScoreAndMatch.push_back(std::make_pair(accScore, pBestKF));
377 if (accScore > bestAccScore)
378 bestAccScore = accScore;
385 float minScoreToRetain = 0.75f * bestAccScore;
387 std::set<WAIKeyFrame*> spAlreadyAddedKF;
388 std::vector<WAIKeyFrame*> vpRelocCandidates;
389 vpRelocCandidates.reserve(lAccScoreAndMatch.size());
390 for (std::list<std::pair<float, WAIKeyFrame*>>::iterator it = lAccScoreAndMatch.begin(), itend = lAccScoreAndMatch.end(); it != itend; it++)
392 const float& si = it->first;
395 if (si > minScoreToRetain)
398 if (!spAlreadyAddedKF.count(pKFi))
400 vpRelocCandidates.push_back(pKFi);
401 spAlreadyAddedKF.insert(pKFi);
406 return vpRelocCandidates;
void add(WAIKeyFrame *pKF)
std::vector< WAIKeyFrame * > DetectLoopCandidates(WAIKeyFrame *pKF, float minCommonWordFactor, float minScore, int *errorCode)
@ LOOP_DETECTION_ERROR_NONE
@ LOOP_DETECTION_ERROR_NO_SIMILAR_CANDIDATES
@ LOOP_DETECTION_ERROR_NO_CANDIDATES_WITH_COMMON_WORDS
std::vector< std::list< WAIKeyFrame * > > mvInvertedFile
WAIKeyFrameDB(WAIOrbVocabulary *voc)
void erase(WAIKeyFrame *pKF)
std::vector< WAIKeyFrame * > DetectRelocalizationCandidates(WAIFrame *F, float minCommonWordFactor, bool applyMinAccScoreFilter=false)
std::vector< WAIKeyFrame * > GetBestCovisibilityKeyFrames(const int &N)
long unsigned int mnRelocQuery
long unsigned int mnLoopQuery
std::set< WAIKeyFrame * > GetConnectedKeyFrames()
double score(WAIBowVector &bow1, WAIBowVector &bow2)
fbow::fBow & getWordScoreMapping()