补充SystemSetting和InitKeyFrame两个类的代码。实际上,由于是通过SystemSetting来读取的相机内参以及ORB特征参数,所以就可以将Tracking.cc中关于读取内参的部分替换掉了。

1. SystemSetting.h

#ifndef SYSTEMSETTING_H
#define SYSTEMSETTING_H #include <string>
#include "ORBVocabulary.h"
#include<opencv2/core/core.hpp> namespace ORB_SLAM2 { class SystemSetting{ //Load camera parameters from setting file
public: SystemSetting(ORBVocabulary* pVoc);
//SystemSetting::SystemSetting(ORBVocabulary* pVoc, KeyFrameDatabase* pKFDB ); bool LoadSystemSetting(const std::string strSettingPath); public:
//The Vocabulary and KeyFrameDatabase
ORBVocabulary* pVocabulary;
//KeyFrameDatabase* pKeyFrameDatabase; //Camera parameters
float width;
float height;
float fx;
float fy;
float cx;
float cy;
float invfx;
float invfy;
float bf;
float b;
float fps;
cv::Mat K;
cv::Mat DistCoef;
bool initialized; //Camera RGB parameters
int nRGB; //ORB feature parameters
int nFeatures;
float fScaleFactor;
int nLevels;
float fIniThFAST;
float fMinThFAST; //other parameters
float ThDepth = -;
float DepthMapFactor = -; }; } //namespace ORB_SLAM2 #endif //SystemSetting

2. SystemSetting.cc

#include <iostream>

#include "SystemSetting.h"

using namespace std;

namespace ORB_SLAM2 {

    SystemSetting::SystemSetting(ORBVocabulary* pVoc):
pVocabulary(pVoc)
{
} //SystemSetting::SystemSetting(ORBVocabulary* pVoc, KeyFrameDatabase* pKFDB):
// pVocabulary(pVoc), pKeyFrameDatabase(pKFDB)
// {
// } bool SystemSetting::LoadSystemSetting(const std::string strSettingPath){
cout<<endl<<"Loading System Parameters form:"<<strSettingPath<<endl;
cv::FileStorage fSettings(strSettingPath, cv::FileStorage::READ);
width = fSettings["Camera.width"];
height = fSettings["Camera.height"];
fx = fSettings["Camera.fx"];
fy = fSettings["Camera.fy"];
cx = fSettings["Camera.cx"];
cy = fSettings["Camera.cy"]; cv::Mat tmpK = cv::Mat::eye(,,CV_32F);
tmpK.at<float>(,) = fx;
tmpK.at<float>(,) = fy;
tmpK.at<float>(,) = cx;
tmpK.at<float>(,) = cy;
tmpK.copyTo(K); cv::Mat tmpDistCoef(,,CV_32F);
tmpDistCoef.at<float>() = fSettings["Camera.k1"];
tmpDistCoef.at<float>() = fSettings["Camera.k2"];
tmpDistCoef.at<float>() = fSettings["Camera.p1"];
tmpDistCoef.at<float>() = fSettings["Camera.p2"];
const float k3 = fSettings["Camera.k3"];
if( k3!= )
{
tmpDistCoef.resize();
tmpDistCoef.at<float>() = k3;
}
tmpDistCoef.copyTo( DistCoef ); bf = fSettings["Camera.bf"];
fps= fSettings["Camera.fps"]; invfx = 1.0f/fx;
invfy = 1.0f/fy;
b = bf /fx;
initialized = true; cout<<"- size:"<<width<<"x"<<height<<endl;
cout<<"- fx:" <<fx<<endl;
cout << "- fy: " << fy << endl;
cout << "- cx: " << cx << endl;
cout << "- cy: " << cy << endl;
cout << "- k1: " << DistCoef.at<float>() << endl;
cout << "- k2: " << DistCoef.at<float>() << endl;
if(DistCoef.rows==)
cout << "- k3: " << DistCoef.at<float>() << endl;
cout << "- p1: " << DistCoef.at<float>() << endl;
cout << "- p2: " << DistCoef.at<float>() << endl;
cout << "- bf: " << bf << endl; //Load RGB parameter
nRGB = fSettings["Camera.RGB"]; //Load ORB feature parameters
nFeatures = fSettings["ORBextractor.nFeatures"];
fScaleFactor = fSettings["ORBextractor.scaleFactor"];
nLevels = fSettings["ORBextractor.nLevels"];
fIniThFAST = fSettings["ORBextractor.iniThFAST"];
fMinThFAST = fSettings["ORBextractor.minThFAST"]; cout << endl << "ORB Extractor Parameters: " << endl;
cout << "- Number of Features: " << nFeatures << endl;
cout << "- Scale Levels: " << nLevels << endl;
cout << "- Scale Factor: " << fScaleFactor << endl;
cout << "- Initial Fast Threshold: " << fIniThFAST << endl;
cout << "- Minimum Fast Threshold: " << fMinThFAST << endl; //Load others parameters, if the sensor is MONOCULAR, the parameters is zero;
//ThDepth = fSettings["ThDepth"];
//DepthMapFactor = fSettings["DepthMapFactor"];
fSettings.release();
return true;
} }

3. InitKeyFrame.h

#ifndef INITKEYFRAME_H
#define INITKEYFRAME_H #include "Thirdparty/DBoW2/DBoW2/BowVector.h"
#include "Thirdparty/DBoW2/DBoW2/FeatureVector.h"
#include "SystemSetting.h"
#include <opencv2/opencv.hpp>
#include "ORBVocabulary.h"
#include "KeyFrameDatabase.h"
//#include "MapPoints.h" namespace ORB_SLAM2
{ #define FRAME_GRID_ROWS 48
#define FRAME_GRID_COLS 64 class SystemSetting;
class KeyFrameDatabase;
//class ORBVocabulary; class InitKeyFrame
{
public:
InitKeyFrame(SystemSetting &SS); void UndistortKeyPoints();
bool PosInGrid(const cv::KeyPoint& kp, int &posX, int &posY);
void AssignFeaturesToGrid(); public: ORBVocabulary* pVocabulary;
//KeyFrameDatabase* pKeyFrameDatabase; long unsigned int nId;
double TimeStamp; float fGridElementWidthInv;
float fGridElementHeightInv;
std::vector<std::size_t> vGrid[FRAME_GRID_COLS][FRAME_GRID_ROWS]; float fx;
float fy;
float cx;
float cy;
float invfx;
float invfy;
float bf;
float b;
float ThDepth;
int N;
std::vector<cv::KeyPoint> vKps;
std::vector<cv::KeyPoint> vKpsUn;
cv::Mat Descriptors; //it's zero for mono
std::vector<float> vRight;
std::vector<float> vDepth; DBoW2::BowVector BowVec;
DBoW2::FeatureVector FeatVec; int nScaleLevels;
float fScaleFactor;
float fLogScaleFactor;
std::vector<float> vScaleFactors;
std::vector<float> vLevelSigma2;
std::vector<float> vInvLevelSigma2;
std::vector<float> vInvScaleFactors; int nMinX;
int nMinY;
int nMaxX;
int nMaxY;
cv::Mat K;
cv::Mat DistCoef; }; } //namespace ORB_SLAM2
#endif //INITKEYFRAME_H

4. InitKeyFrame.cc

#include "InitKeyFrame.h"
#include <opencv2/opencv.hpp>
#include "SystemSetting.h" namespace ORB_SLAM2
{ InitKeyFrame::InitKeyFrame(SystemSetting &SS):pVocabulary(SS.pVocabulary)//, pKeyFrameDatabase(SS.pKeyFrameDatabase)
{
fx = SS.fx;
fy = SS.fy;
cx = SS.cx;
cy = SS.cy;
invfx = SS.invfx;
invfy = SS.invfy;
bf = SS.bf;
b = SS.b;
ThDepth = SS.ThDepth; nScaleLevels = SS.nLevels;
fScaleFactor = SS.fScaleFactor;
fLogScaleFactor = log(SS.fScaleFactor);
vScaleFactors.resize(nScaleLevels);
vLevelSigma2.resize(nScaleLevels);
vScaleFactors[] = 1.0f;
vLevelSigma2[] = 1.0f;
for ( int i = ; i < nScaleLevels; i ++ )
{
vScaleFactors[i] = vScaleFactors[i-]*fScaleFactor;
vLevelSigma2[i] = vScaleFactors[i]*vScaleFactors[i];
} vInvScaleFactors.resize(nScaleLevels);
vInvLevelSigma2.resize(nScaleLevels);
for ( int i = ; i < nScaleLevels; i ++ )
{
vInvScaleFactors[i] = 1.0f/vScaleFactors[i];
vInvLevelSigma2[i] = 1.0f/vLevelSigma2[i];
} K = SS.K; DistCoef = SS.DistCoef; if( SS.DistCoef.at<float>()!=0.0)
{
cv::Mat mat(,,CV_32F);
mat.at<float>(,) = 0.0;
mat.at<float>(,) = 0.0;
mat.at<float>(,) = SS.width;
mat.at<float>(,) = 0.0;
mat.at<float>(,) = 0.0;
mat.at<float>(,) = SS.height;
mat.at<float>(,) = SS.width;
mat.at<float>(,) = SS.height; mat = mat.reshape();
cv::undistortPoints(mat, mat, SS.K, SS.DistCoef, cv::Mat(), SS.K);
mat = mat.reshape(); nMinX = min(mat.at<float>(,), mat.at<float>(,));
nMaxX = max(mat.at<float>(,), mat.at<float>(,));
nMinY = min(mat.at<float>(,), mat.at<float>(,));
nMaxY = max(mat.at<float>(,), mat.at<float>(,));
}
else
{
nMinX = 0.0f;
nMaxX = SS.width;
nMinY = 0.0f;
nMaxY = SS.height;
} fGridElementWidthInv=static_cast<float>(FRAME_GRID_COLS)/(nMaxX-nMinX);
fGridElementHeightInv=static_cast<float>(FRAME_GRID_ROWS)/(nMaxY-nMinY); } void InitKeyFrame::UndistortKeyPoints()
{
if( DistCoef.at<float>() == 0.0)
{
vKpsUn = vKps;
return;
} cv::Mat mat(N,,CV_32F);
for ( int i = ; i < N; i ++ )
{
mat.at<float>(i,) = vKps[i].pt.x;
mat.at<float>(i,) = vKps[i].pt.y;
} mat = mat.reshape();
cv::undistortPoints(mat, mat, K, DistCoef, cv::Mat(), K );
mat = mat.reshape(); vKpsUn.resize(N);
for( int i = ; i < N; i ++ )
{
cv::KeyPoint kp = vKps[i];
kp.pt.x = mat.at<float>(i,);
kp.pt.y = mat.at<float>(i,);
vKpsUn[i] = kp;
}
} void InitKeyFrame::AssignFeaturesToGrid()
{
int nReserve = 0.5f*N/(FRAME_GRID_COLS*FRAME_GRID_ROWS);
for ( unsigned int i = ; i < FRAME_GRID_COLS; i ++ )
{
for ( unsigned int j = ; j < FRAME_GRID_ROWS; j ++)
vGrid[i][j].reserve(nReserve);
} for ( int i = ; i < N; i ++ )
{
const cv::KeyPoint& kp = vKpsUn[i];
int nGridPosX, nGridPosY;
if( PosInGrid(kp, nGridPosX, nGridPosY))
vGrid[nGridPosX][nGridPosY].push_back(i);
}
} bool InitKeyFrame::PosInGrid(const cv::KeyPoint &kp, int &posX, int &posY)
{
posX = round((kp.pt.x-nMinX)*fGridElementWidthInv);
posY = round((kp.pt.y-nMinY)*fGridElementHeightInv); if(posX< || posX>=FRAME_GRID_COLS ||posY< || posY>=FRAME_GRID_ROWS)
return false;
return true;
} }

ORB-SLAM2 地图加载2的更多相关文章

  1. ORB-SLAM2 地图加载

    一.前面说了ORB-SLAM地图的保存部分,继续说地图如何加载,因为加载部分相比保存要稍微复杂一些,所以要多说一点. 二.ORB-SLAM2地图加载构成 首先同样是在头文件中声明加载函数,包含地图点和 ...

  2. AMap地图加载完成事件

    <!doctype html> <html> <head> <meta charset="utf-8"> <meta http ...

  3. Openlayers+Geoserver(一):项目介绍以及地图加载

           项目验收完,趁着事情不是很多,对这个项目进行梳理.我主要负责地图模块,网站其他模块主要有两个,一个是报表,主要是100多张报表,技术没有难度,主要是工作量的问题.另一个是数据的校验,就是 ...

  4. ArcGIS API for Silverlight地图加载众多点时,使用Clusterer解决重叠问题

    原文:ArcGIS API for Silverlight地图加载众多点时,使用Clusterer解决重叠问题 问题:如果在地图上加载成百上千工程点时,会密密麻麻,外观不是很好看,怎么破? 解决方法: ...

  5. Android高清巨图加载方案

    1.今天看了鸿洋的<Android高清巨图加载方案>一文,对加载高清巨图时的解决方案有了一定的认识. 思路为: 提供一个设置图片的入口. 重写onTouchEvent,在里面根据用户移动的 ...

  6. arcgis 瓦片图加载规则(转载)

    arcgis 瓦片图加载规则 最近需要做地图离线的功能,要能下载指定区域的瓦片图,我们都知道如何加载谷歌和天地图的加载规则,但是网上貌似没有找到如何加载arcgis自己发布的瓦片图规则,好不容易找到一 ...

  7. Leaflet+heatmap实现离线地图加载和热力图应用

    本人博客主页:http://www.cnblogs.com/webbest/ 2017年春节已经过完,新一年的奋斗也刚刚开始.今年要经历的挑战也是大大的...不扯了. 年底前软件项目相对较多,恰巧在年 ...

  8. arcgis api 3.x for js 地图加载多个 SHP 图层压缩以及 json 文件展示(附源码下载)

    前言 关于本篇功能实现用到的 api 涉及类看不懂的,请参照 esri 官网的 arcgis api 3.x for js:esri 官网 api,里面详细的介绍 arcgis api 3.x 各个类 ...

  9. 微软必应地图加载错误:Uncaught TypeError: Microsoft.Maps.Location is not a constructor

    微软必应地图在chrome浏览器加载错误:Uncaught TypeError: Microsoft.Maps.Location is not a constructor, 原因是没有等待地图API加 ...

  10. orb slam2 双目摄像头

    主要参考了http://blog.csdn.net/awww797877/article/details/51171099这篇文章,其中需要添加的是:export ROS_PACKAGE_PATH=$ ...

随机推荐

  1. 趣谈Linux操作系统学习笔记:第二十四讲

    一.小内存的分配基础 1.kmem_cache_alloc_node的作用 通过这段代码可以看出,它调用了kmem_cache_alloc_node函数,在task_struct的缓存区域task_s ...

  2. Ubuntu Idea 快捷键 Ctrl+Alt+S 无法使用解决

    Idea 里习惯了用 Ctrl+Alt+S 打开设置界面,在 Ubuntu 下会因为快捷键冲突无法使用 系统快捷键 打开系统设置中的快捷键设置,按 Backspace 键禁用 Fcitx 如果你的输入 ...

  3. Python连载47-json文件、正则表达式初步

    一.在线工具 1.https://www.sojson.com/ 2.http://www.w3cshool.com.cn/json/ 3.http://www.runoob.com/json/jso ...

  4. Python连载45-XML解析(使用minidom和etree分别示例)

    一.我们对XML的读取进行一波演示 import xml.dom.minidom #负责解析xml文件的包 from xml.dom.minidom import parse ​ #使用minidom ...

  5. 12306抢票带来的启示:看我如何用Go实现百万QPS的秒杀系统

    本文为开源实验性工程:“github.com/GuoZhaoran/spikeSystem”的配套文章,原作者:“绘你一世倾城”,现为:猎豹移动php开发工程师,感谢原作者的技术分享. 1.引言 Go ...

  6. pytest框架之mark标签

    对测试用例打标签,在运行测试用例的时候,可根据标签名来过滤要运行的用例. 一.注册标签名 1.创建pytest.ini文件,在文件中按如下方式添加标签名: [pytest] markers = smo ...

  7. jQuery 源码分析(十六) 事件系统模块 底层方法 详解

    jQuery事件系统并没有将事件监听函数直接绑定到DOM元素上,而是基于数据缓存模块来管理监听函数的,事件模块代码有点多,我把它分为了三个部分:分底层方法.实例方法和便捷方法.ready事件来讲,好理 ...

  8. shell 命令 tar -zxvf 解压 tar -zcvf 压缩

    tar -zxvf 解压 tar -zcvf 压缩

  9. MECE分析法

      概述 MECE分析法,是麦肯锡的第一个女咨询顾问 Barbara Minto 在金字塔原理中提出的一个很重要的原则. MECE分析法,全称Mutually Exclusive Collective ...

  10. 五分钟搞定 HTTPS 配置,二哥手把手教

    01.关于 FreeSSL.cn FreeSSL.cn 是一个免费提供 HTTPS 证书申请.HTTPS 证书管理和 HTTPS 证书到期提醒服务的网站,旨在推进 HTTPS 证书的普及与应用,简化证 ...