设计目的
This post would be focussing on Monocular Visual Odometry, and how we can implement it in OpenCV/C++.
设计要求
设计流程
畸变校正
使用OpenCV自带的库函数;
特征提取
仍然是FAST特征点提取,代码如下:
void featureDetection(Mat img_1, vector<Point2f>& points1) {
vector<KeyPoint> keypoints_1;
int fast_threshold = 20;
bool nonmaxSuppression = true;
FAST(img_1, keypoints_1, fast_threshold, nonmaxSuppression);
KeyPoint::convert(keypoints_1, points1, vector<int>());
}
特征跟踪
采用OpenCV库函数:KLT tracker
针对跟踪失败,进行重检测跟踪。
本质矩阵(基础矩阵)
- RANSAC
- 5-Points法
OpenCV 库函数:
E = findEssentialMat(points2, points1, focal, pp, RANSAC, 0.999, 1.0, mask)
计算R,t
通过本质矩阵E (Essential Matrix)计算R,t,这里采用SVD和旋转矩阵的约束条件,得到:
这里也通过调用OpenCV函数:
recoverPose(E, points2, points1, R, t, focal, pp, mask)
构造轨迹
通过R,t来跟踪相机位姿,其中,平移scale t需要提前确定,我们可以通过外部输入。
启发思考
大多数计算机视觉算法是不完整的,没有针对各种意外情况的发生,视觉测距也不例外。所以,我们需要有个前提:运动主方向。
结果
得到数据很容易,但是,怎么解决意外情况,任重而道远。