SLAM十四讲---前端0.1---相机/帧/地图点/地图/配置类的定义

slam十四讲——RGBD的视觉里程计

定义了几个类,分别为相机类(Camera)、帧类(Frame)、地图点类(MapPoint)、地图类(Map)、配置类(Config)

下面给出大纲:

1. 相机类Camera

相机类中储存了相机内参,以及定义了一些坐标系转换的接口。

类成员变量:

(1)智能指针
typedef std::shared_ptr Ptr;
(2)相机内参
float fx_, fy_, cx_, cy_, depth_scale_; // Camera intrinsics

类成员函数:
(1)无参构造——应该没啥用
Camera();
(2)有参构造
Camera ( float fx, float fy, float cx, float cy, float depth_scale=0 ) :
fx_ ( fx ), fy_ ( fy ), cx_ ( cx ), cy_ ( cy ), depth_scale_ ( depth_scale )

2. 帧类Frame

帧类中存储了编号、当前帧位姿、当前帧的RGB图像和深度图像

类成员变量:
(1)智能指针
typedef std::shared_ptr Ptr;
(2)帧的编号id
unsigned long id_; // id of this frame
(3)时间戳
double time_stamp_; // when it is recorded
(4)当前帧位姿(世界->相机)
SE3 T_c_w_; // transform from world to camera
(5)相机模型以及需要他其中的一系列坐标系转换的接口
Camera::Ptr camera_; // Pinhole RGBD Camera model 相机模型,得用到当前帧的相机模型,来实现坐标系转换的功能
(5)当前帧的rgb图像和深度图
Mat color_, depth_; // color and depth image

类成员函数:
(1)无参构造
Frame();
(2)有参构造
Frame( long id, double time_stamp=0, SE3 T_c_w=SE3(), Camera::Ptr camera=nullptr, Mat color=Mat(), Mat depth=Mat() );
(3)析构
~Frame();
(4)构造一帧
// factory function
static Frame::Ptr createFrame(); // 构造一帧,里面有id
(5)给2d点,返回深度值
// find the depth in depth map
double findDepth( const cv::KeyPoint& kp ); // 返回深度值
(6)得到当前帧相机光心在世界坐标的位置(光心位置)
// Get Camera Center 得到当前帧相机光心在世界坐标的位置
Vector3d getCamCenter() const;
(7)判断某个世界点是否在视野内
// check if a point is in this frame
bool isInFrame( const Vector3d& pt_world ); // 判断某个点是否在视野内

3. 地图点类MapPoint

地图点类存储了编号、坐标、方向、描述子等

这里有个很重要的概念:需要存储其描述子

是为了当推断相机位姿的时候,提取图像特征点后,特征点的描述子与3d地图点的描述子进行比较,匹配,可以认为这个3d点投影到这个位姿相机图像平面上的时候,就是与之描述子匹配的那个点。

类成员变量:
(1)智能指针
typedef shared_ptr Ptr;
(2)id编号
unsigned long id_; // ID
(3)3d坐标
Vector3d pos_; // Position in world
(4)方向
Vector3d norm_; // Normal of viewing direction // 归一化后的,代表了方向
(5)描述子,为了匹配用
Mat descriptor_; // Descriptor for matching // 必须有描述子,以便于根据二维图像中的特征点进行匹配,从而估计相机的位姿
(6)被观测到的次数
int observed_times_; // being observed by feature matching algo.
(7)作为内点的次数
int correct_times_; // being an inliner in pose estimation

类成员函数:
(1)无参构造
MapPoint();
(2)有参构造,输入id,3d位置,方向
MapPoint( long id, Vector3d position, Vector3d norm );
(3)创建地图点
// factory function
static MapPoint::Ptr createMapPoint();

4. 地图类Map

管理所有的地图点,VO的匹配过程只需要和Map类打交道即可。

成员变量:

(1)智能指针
typedef shared_ptr Ptr;
(2)哈希容器unorderedmap(散列),存储地图点,便于随时添加和删除
unordered_map<unsigned long, MapPoint::Ptr > map_points_; // all landmarks
(3)哈希容器unorderedmap(散列),存储关键帧,便于随时添加和删除
unordered_map<unsigned long, Frame::Ptr > keyframes_; // all key-frames

成员函数:

(1)无参构造
Map() {}
(2)插入关键帧
void insertKeyFrame( Frame::Ptr frame );
(3)插入地图点
void insertMapPoint( MapPoint::Ptr map_point );

从这里可见,map维护的是一系列关键帧(所有普通帧的子集)和一堆地图点。

5. 配置类Config

负责参数文件的读取,是一个全局对象。想读参数的时候就拿它读一下

成员变量:

(1)智能指针
static std::shared_ptr config_;
(2)理解为用于数据存取操作的句柄
cv::FileStorage file_;

成员函数:

(1) 析构函数,关闭文件
~Config(); // close the file when deconstructing
(2)读取文件并赋予句柄 file_;
// set a new config file
static void setParameterFile( const std::string& filename );
(3)根据键值获取参数值
// access the parameter values
template< typename T >
static T get( const std::string& key )
{
return T( Config::config_->file_[key] );
}
获取参数的方法,在yaml文件中写入Camera.fx:500
在这里插入图片描述

常识补充:
1.讲构造函数设置为私有,是为了不能让其在别处建立,以便于其形成“单例模式”(config类中)
2.设置各种智能指针的原因是,能够自动析构,防止内存泄露(各个类中均有)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值