本文详细介绍了如何使用特征点法构建视觉里程计,通过代码实践来解析关键步骤,包括图像预处理、特征检测与匹配、姿态估计等,深入探讨SLAM(Simultaneous Localization and Mapping)技术的应用。
摘要由CSDN通过智能技术生成
#ifndef VISUALODOMETRY_H#define VISUALODOMETRY_H#include"myslam/common_include.h"#include"myslam/map.h"#include<opencv2/features2d/features2d.hpp>namespace myslam
{
classVisualOdometry{
public://定义指向自身的智能指针,在后面传递参数是使用VisualOdometry::Ptr即可typedef shared_ptr<VisualOdometry> Ptr;//定义枚举来表征VO状态,分别为:初始化、正常、丢失enum VOState {
INITIALIZING=-1,
OK=0,
LOST
};//这里为两两帧VO所用到的参考帧和当前帧。还有VO状态和整个地图。
VOState state_;// current VO status
Map::Ptr map_;// map with all frames and map points
Frame::Ptr ref_;// reference key-frame
Frame::Ptr curr_;// current frame //这里是两帧匹配需要的:keypoints,descriptors,matches,相比0.2去掉了关于参考帧的东西,3D点,描述子等
cv::Ptr<cv::ORB> orb_;// orb detector and computer
vector<cv::KeyPoint> keypoints_curr_;// keypoints in current frame
Mat descriptors_curr_;// descriptor in current frame //在匹配器中,所需要的匹配变成了地图点和帧中的关键点
cv::FlannBasedMatcher matcher_flann_;// flann matcher
vector<MapPoint::Ptr> match_3dpts_;// matched 3d points
vector<int> match_2dkp_index_;// matched 2d pixels (index of kp_curr)//这里为匹配结果T,还有表征结果好坏的内点数和丢失数
SE3 T_c_w_estimated_;// the estimated pose of current frame int num_inliers_;// number of inlier features in icpint num_lost_;// number of lost times// parameters int num_of_features_;// number of featuresdouble scale_factor_;// scale in image pyramidint level_pyramid_;// number of pyramid levelsfloat match_ratio_;// ratio for selecting good matchesint max_num_lost_;// max number of continuous lost timesint min_inliers_;// minimum inliers//用于判定是否为关键帧的标准,说白了就是规定一定幅度的旋转和平移,大于这个幅度就归为关键帧double key_frame_min_rot;// minimal rotation of two key-framesdouble key_frame_min_trans;// minimal translation of two key-framesdouble map_point_erase_ratio_;// remove map point ratiopublic:// functions VisualOdometry();~VisualOdometry();//这个函数为核心处理函数,将帧添加进来,然后处理booladdFrame( Frame::Ptr frame );// add a new frame protected:// inner operation //一些内部处理函数,这块主要是特征匹配的voidextractKeyPoints();voidcomputeDescriptors();voidfeatureMatching();voidposeEstimationPnP();//增加的优化地图的函数,这个函数可能实现的就是对整个后端地图的优化voidoptimizeMap();//这里是关键帧的一些功能函数//增加地图点函数voidaddKeyFrame();voidaddMapPoints();boolcheckEstimatedPose();boolcheckKeyFrame();//增加的取得视角函数doublegetViewAngle( Frame::Ptr frame, MapPoint::Ptr point );};}#endif// VISUALODOMETRY_H