《SLAM十四讲》8.3 使用LK光流法useLK.hpp

LK光流法的步骤:

1.对第一帧提取FAST特征点存到keypoints中
2.对其他帧用LK跟踪特征点
3.更新keypoints列表,从prev_keypoints到next_keypoints
4.画出 keypoints圆圈

本博客不讲解理论部分,直接上主程序。因为本博客是博主的学习分享帖子,可能有些繁琐,见谅~

#include <iostream>
#include<fstream>//fstream是对文件操作的头文件
#include <list>
#include <vector>
#include <chrono>//与时间有关的库
using namespace std;

#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/features2d/features2d.hpp>
#include <opencv2/video/tracking.hpp>
//光流法需要include<opencv2/video/tracking.hpp>,用到列表,所以要include<list><vector>


int main( int argc, char** argv )
{
   
    if ( argc != 2 )//启动条件,判断程序是否打开一个文件夹
    {
   
        cout<<"usage: useLK path_to_dataset"<<endl;
        return 1;
    }
    
    string path_to_dataset = argv[1];//获取命令行输入的文件名,也就是图像的存储路径,格式保存为string
    
    string associate_file = path_to_dataset + "/associate.txt";//拼接,形成文件地址用于获取associate文件地址
    
    ifstream fin( associate_file );//打开associate_file下的txt文件,以fin的方式打开,如果找不到文件则不会创建相关度的文件夹
    
    string rgb_file, depth_file, time_rgb, time_depth;//因为associate文件的每一行分别是time_color,color,time_depth,depth.所以定义这4个路径,方便之后读取深度图和彩色图。
    
    list< cv::Point2f > keypoints; // 因为要删除跟踪失败的点,使用list
    
    cv::Mat color, depth, last_color;
    
    for ( int index=0; index<100; index++ )
    {
   
        //读入颜色和深度图像
        fin>>time_rgb>>rgb_file>>time_depth>>depth_file;
        
        color = cv::imread( path_to_dataset+"/"+rgb_file );
        
        depth = cv::imread
  • 2
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值