From 6fc712c15d1d9baa7a7a81529404a432608eb276 Mon Sep 17 00:00:00 2001 From: matlabbe Date: Tue, 17 Dec 2013 22:36:09 +0000 Subject: [PATCH] Fixed an odometry crash when there is only 1 word in the dictionary (and NNDR is activated) git-svn-id: http://rtabmap.googlecode.com/svn/trunk/rtabmap@1056 f169173b-cf89-36c8-b27e-44dbe73f0c83 --- corelib/src/VWDictionary.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/corelib/src/VWDictionary.cpp b/corelib/src/VWDictionary.cpp index 69884305..dd8b139c 100644 --- a/corelib/src/VWDictionary.cpp +++ b/corelib/src/VWDictionary.cpp @@ -454,7 +454,7 @@ std::list VWDictionary::addNewWords(const cv::Mat & descriptors, UTimer timerLocal; timerLocal.start(); - if(!_dataTree.empty()) + if(!_dataTree.empty() && _dataTree.rows >= (int)k) { //Find nearest neighbors UDEBUG("newPts.total()=%d ", newPts.total()); @@ -469,7 +469,7 @@ std::list VWDictionary::addNewWords(const cv::Mat & descriptors, std::map fullResults; // Contains results from the kd-tree search and the naive search in new words this->naiveNNSearch(newWords, newPts.ptr(i), _dim, fullResults, k); - if(!_dataTree.empty()) + if(!_dataTree.empty() && _dataTree.rows >= (int)k) { for(unsigned int j=0; j VWDictionary::findNN(const std::list & vws, bool } ULOGGER_DEBUG("Preparation time = %fs", timer.ticks()); - if(!_dataTree.empty()) + if(!_dataTree.empty() && _dataTree.rows >= (int)k) { _nn->search(newPts, results, dists, k, _maxLeafs); } @@ -661,7 +661,7 @@ std::vector VWDictionary::findNN(const std::list & vws, bool std::map mapIndexIdNotIndexed; unsigned int unreferencedWordsCount = _visualWords.size() - _mapIndexId.size(); - if(searchInNewlyAddedWords && unreferencedWordsCount) + if(searchInNewlyAddedWords && unreferencedWordsCount && unreferencedWordsCount >= (int)k) { cv::Mat dataNotIndexed = cv::Mat::zeros(unreferencedWordsCount, _dim, CV_32F); unsigned int index = 0; @@ -697,7 +697,7 @@ std::vector VWDictionary::findNN(const std::list & vws, bool for(unsigned int j=0; j= (int)k) { dist = dists.at(i,j); fullResults.insert(std::pair(dist, uValue(_mapIndexId, results.at(i,j)))); @@ -832,7 +832,7 @@ void VWDictionary::naiveNNSearch(const std::list & words, const fl const float * dw = 0; bool goodMatch; - if(!words.size() || k == 0) + if(!words.size() || k == 0 || words.size() < k) { return; }