视觉里程计(VO)的实现(一)

代码基于高翔博士(《视觉SLAM十四讲》作者)博客,并在在ubuntu 16.0.4 +opencv3.4.1 环境下适配。
原博客网址:https://www.cnblogs.com/gaoxiang12/p/4659805.html

1.具体说明:

1. ORB算法适配
前辈使用的应该是opencv2版本,所以使用ORB算法的代码为:

cv::Ptr<cv::FeatureDetector> detector;
cv::Ptr<cv::DescriptorExtractor> descriptor;
etector = cv::FeatureDetector::create("ORB");
descriptor = cv::DescriptorExtractor::create("ORB"); 
vector< cv::KeyPoint > kp1, kp2; //关键点
detector->detect( rgb1, kp1 );  //提取关键点
detector->detect( rgb2, kp2 ); 

详情参见前辈github:
https://github.com/gaoxiang12/rgbd-slam-tutorial-gx/blob/master/part III/src/detectFeatures.cpp

opencv3版本下的适配代码为:

cv::Ptr<cv::ORB> orb = cv::ORB::create();
vector< cv::KeyPoint > kp1, kp2; //关键点
orb->detect(rgb1, kp1);
orb->detect(rgb2, kp2);

我的github:https://github.com/raopei/mySlam
2. 修改错误参数
使用 cv::solvePnPRansac函数求解相机位姿时参数出错。(没有验证opencv2版本下是否正确,在opencv 3.4.1下报错)
前辈代码:

cv::solvePnPRansac( pts_obj, pts_img, cameraMatrix, cv::Mat(), rvec, tvec, false, 100, 1.0, 100, inliers );

其中inliers参数前一个参数是有误的(我使用的opencv版本下报错)

OpenCV(3.4.1) Error: Assertion failed (npoints >= 4 && npoints == std::max(ipoints.checkVector(2, 5), ipoints.checkVector(2, 6))) in solvePnPRansac, file /home/raopei/音乐/opencv-3.4.1/modules/calib3d/src/solvepnp.cpp, line 253
terminate called after throwing an instance of 'cv::Exception'

转到函数cv::solvePnPRansac的声明下发现1.0和inliers参数之间的100错误的,应该设置成(0,1)之间的数字。如:

cv::solvePnPRansac( pts_obj, pts_img, cameraMatrix, cv::Mat(), rvec, tvec, false, 100, 1.0, 0.99, inliers );

3.数据路径问题
原代码采用相对路径:

cv::Mat rgb1 = cv::imread( "./data/rgb1.png");

经过测试在我所用的环境下无法读入图像。
更改为绝对路径后正常。如:

cv::Mat rgb1 = cv::imread( "/home/raopei/mySlam/data/rgb1.png");

运行截图:
在这里插入图片描述

在这里插入图片描述

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章