ORBSLAM2 Win10 VS2017 二进制词袋修改_滥觞LanShang的博客-CSDN博客
版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/weixin_45675146/article/details/121559964
————————————————
版权声明:本文为CSDN博主「滥觞LanShang」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/weixin_45675146/article/details/121559964ORBSLAM2 Win10 VS2017 二进制词袋修改_滥觞LanShang的博客-CSDN博客
1. 下载二进制词袋 ORBvoc.bin 放在 orbsalm2 / Vocabulary 下
GitHub - nxyzgf/sgg-dbow2: Lib file of DBoW2 compiled by VS15 ORBvoc.binLib file of DBoW2 compiled by VS15 ORBvoc.bin. Contribute to nxyzgf/sgg-dbow2 development by creating an account on GitHub.https://github.com/nxyzgf/sgg-dbow22. 修改 DBOW2 文件夹里面 TemplatedVocabulary.h 文件修改两处内容
240 行左右
/**
* Loads the vocabulary from a text file
* @param filename
*/
bool loadFromTextFile(const std::string &filename);
//在这个位置
// 添加下面这一句
bool loadFromBinaryFile(const std::string &filename);
1440 函数下面
在 1460 左右
添加这个
template<class TDescriptor, class F>
bool TemplatedVocabulary<TDescriptor, F>::loadFromBinaryFile(const std::string &filename) {
fstream f;
f.open(filename.c_str(), ios_base::in | ios::binary);
unsigned int nb_nodes, size_node;
f.read((char*)&nb_nodes, sizeof(nb_nodes));
f.read((char*)&size_node, sizeof(size_node));
f.read((char*)&m_k, sizeof(m_k));
f.read((char*)&m_L, sizeof(m_L));
f.read((char*)&m_scoring, sizeof(m_scoring));
f.read((char*)&m_weighting, sizeof(m_weighting));
createScoringObject();
m_words.clear();
m_words.reserve(pow((double)m_k, (double)m_L + 1));
m_nodes.clear();
m_nodes.resize(nb_nodes + 1);
m_nodes[0].id = 0;
char buf[size_node]; int nid = 1;
while (!f.eof()) {
f.read(buf, size_node);
m_nodes[nid].id = nid;
// FIXME
const int* ptr = (int*)buf;
m_nodes[nid].parent = *ptr;
//m_nodes[nid].parent = *(const int*)buf;
m_nodes[m_nodes[nid].parent].children.push_back(nid);
m_nodes[nid].descriptor = cv::Mat(1, F::L, CV_8U);
memcpy(m_nodes[nid].descriptor.data, buf + 4, F::L);
m_nodes[nid].weight = *(float*)(buf + 4 + F::L);
if (buf[8 + F::L]) { // is leaf
int wid = m_words.size();
m_words.resize(wid + 1);
m_nodes[nid].word_id = wid;
m_words[wid] = &m_nodes[nid];
}
else
m_nodes[nid].children.reserve(m_k);
nid += 1;
}
f.close();
return true;
}
// --------------------------------------------------------------------------
3. System.cc 文件修改
65 行左右 修改为
mpVocabulary = new ORBVocabulary();
// bool bVocLoad = mpVocabulary->loadFromTextFile(strVocFile);
bool bVocLoad = mpVocabulary->loadFromBinaryFile(strVocFile);
if(!bVocLoad)
{
cerr << "Wrong path to vocabulary. " << endl;
cerr << "Falied to open at: " << strVocFile << endl;
exit(-1);
}
4. 参考这个
如何将ORBSLAM2由终端运行改成vscode下运行_DidYouLearnSLAMToday的博客-CSDN博客
把里面
string voc_path = "/home/u1/ORB_SLAM2_debug/Vocabulary/ORBvoc.txt";
的 txt 改成 bin