From 326380bf2f4835802beb43f4c06296bb748e970f Mon Sep 17 00:00:00 2001 From: Nathan Hughes Date: Fri, 3 Feb 2023 19:34:16 +0000 Subject: [PATCH] fix issue with vocab loading taking to long with system opencv --- CMakeLists.txt | 2 +- fix_fs_iter.patch | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+), 1 deletion(-) create mode 100644 fix_fs_iter.patch diff --git a/CMakeLists.txt b/CMakeLists.txt index aac6094..3e8b66d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -12,7 +12,7 @@ ExternalProject_Add(dbow2_src GIT_REPOSITORY https://github.com/dorian3d/DBoW2.git GIT_TAG master UPDATE_COMMAND "" - #PATCH_COMMAND "" + PATCH_COMMAND patch -p1 < ${CMAKE_CURRENT_LIST_DIR}/fix_fs_iter.patch CONFIGURE_COMMAND cd ../dbow2_src && cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX:PATH=${CATKIN_DEVEL_PREFIX} -DBUILD_Demo=Off . diff --git a/fix_fs_iter.patch b/fix_fs_iter.patch new file mode 100644 index 0000000..bed70a6 --- /dev/null +++ b/fix_fs_iter.patch @@ -0,0 +1,36 @@ +diff --git a/include/DBoW2/TemplatedVocabulary.h b/include/DBoW2/TemplatedVocabulary.h +index 6d8d621..c95e72e 100644 +--- a/include/DBoW2/TemplatedVocabulary.h ++++ b/include/DBoW2/TemplatedVocabulary.h +@@ -1473,12 +1473,12 @@ void TemplatedVocabulary::load(const cv::FileStorage &fs, + m_nodes.resize(fn.size() + 1); // +1 to include root + m_nodes[0].id = 0; + +- for(unsigned int i = 0; i < fn.size(); ++i) ++ for(auto iter = fn.begin(); iter != fn.end(); ++iter) + { +- NodeId nid = (int)fn[i]["nodeId"]; +- NodeId pid = (int)fn[i]["parentId"]; +- WordValue weight = (WordValue)fn[i]["weight"]; +- std::string d = (std::string)fn[i]["descriptor"]; ++ NodeId nid = (int)(*iter)["nodeId"]; ++ NodeId pid = (int)(*iter)["parentId"]; ++ WordValue weight = (WordValue)(*iter)["weight"]; ++ std::string d = (std::string)(*iter)["descriptor"]; + + m_nodes[nid].id = nid; + m_nodes[nid].parent = pid; +@@ -1493,10 +1493,10 @@ void TemplatedVocabulary::load(const cv::FileStorage &fs, + + m_words.resize(fn.size()); + +- for(unsigned int i = 0; i < fn.size(); ++i) ++ for(auto iter = fn.begin(); iter != fn.end(); ++iter) + { +- NodeId wid = (int)fn[i]["wordId"]; +- NodeId nid = (int)fn[i]["nodeId"]; ++ NodeId wid = (int)(*iter)["wordId"]; ++ NodeId nid = (int)(*iter)["nodeId"]; + + m_nodes[nid].word_id = wid; + m_words[wid] = &m_nodes[nid];