SLAM实践:ORB_SLAM2与D435(二)

本文介绍了如何将D435的color和depth数据实时输入到ORB_SLAM2系统中,重点在于程序的修改与运行,包括数据获取、ORB_SLAM的调整以及CMakeLists.txt的更新。通过简化原始示例,省去了数据读取和颜色-深度匹配步骤,实现了实时SLAM系统的构建。虽然标定部分未完成,但已能成功运行并显示相应画面。
摘要由CSDN通过智能技术生成

程序修改与运行---构建实时系统

源文件下载:

https://download.csdn.net/download/ly1997th/10394408
https://download.csdn.net/download/ly1997th/1039440

1. 从D435中获取color和depth数据,在librealSense/examples/save-to-disk中,可以看到数据是如何获取的。首先得到depth数据,然后获得color数据,然后存入磁盘。在这里,我们可以使用这种方法获得数据(可以尝试不去存磁盘,直接把realsense的数据流转变为Mat类型,传给ORB_SLAM,但是我没有做出来)同时,需要注意的是,ORB_SLAM还需要时间戳,在veido_frame类(其实是在基类frame)中可以找到函数get_timestamp(),获得时间戳。最后,将这部分内容转化为函数

double LoadImages(cv::Mat &imRGB,cv::Mat &imD)

            1.1 原始示例中代码

    for (auto&& frame : pipe.wait_for_frames())
    {
        // We can only save video frames as pngs, so we skip the rest
        if (auto vf = frame.as<rs2::video_frame>())
        {
            auto stream = frame.get_profile().stream_type();
            // Use the colorizer to get an rgb image for the depth stream
            if (vf.is<rs2::depth_frame>()) vf = color_map(frame);

            // Write images to disk
            std::stringstream png_file;
            png_file << "rs-save-to-disk-output-" << vf.get_profile().stream_name() << ".png";
            stbi_write_png(png_file.str().c_str(), vf.get_width(), vf.get_height(),
                           vf.get_bytes_per_pixel(), vf.get_data(), vf.get_stride_in_bytes());
            std::cout << "Saved " << png_file.str() << std::endl;

            // Record per-frame metadata for UVC streams
            // std::stringstream csv_file;
            // csv_file << "rs-save-to-disk-output-" << vf.get_profile().stream_name()
            //          << "-metadata.csv";
            // metadata_to_csv(vf, csv_file.str());
        }
    }

            1.2  double LoadImages(cv::Mat &imRGB,cv::Mat &imD)

double LoadImages(cv::Mat &imRGB,cv::Mat &imD)
{
    // Declare depth colorizer for pretty visualization of depth data
    rs2::colorizer color_map;

    // Declare RealSense pipeline, encapsulating the actual device and sensors
    rs2::pipeline pipe;
    // Start streaming with default recommended configuration
    pipe.start();

    // Wait for the next set of frames from the camera. Now that autoexposure, etc.
    // has settled, we will write these to disk
    int flag=0;
    double timestamp=0.0;
    int ping=1000;
    for (auto&& frame : pipe.wait_for_frames(ping))
    {
        // We can only save video frames as pngs, so we sk
评论 7
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值