ORB-SLAM稠密点云地图构建(黑白+彩色)+ pcd文件以八叉树形式表示

这篇具有很好参考价值的文章主要介绍了ORB-SLAM稠密点云地图构建(黑白+彩色)+ pcd文件以八叉树形式表示。希望对大家有所帮助。如果存在错误或未考虑完全的地方,请大家不吝赐教,您也可以点击"举报违法"按钮提交疑问。

pcl1.8.1
VTK 7.1.1
版本一定要对好,如果安装了不符的版本如我之前安的pcl1.1.3和VTK8.2 一定要卸载干净不然会一直报错
,不同版本的pcl和vtk是无法共存的,并且光把包删除是不够的,要去/usr下面使用命令行(先搜索再一起删掉)

sudo rm -r /path/想删除的库

使用高翔老师的源码ORB-SLAM2-modified
运行前要先把数据集图片和深度对齐
先去官网下载associate.py文件 https://vision.in.tum.de/data/datasets/rgbd-dataset/tools
associate.py的内容

#!/usr/bin/python
# Software License Agreement (BSD License)
#
# Copyright (c) 2013, Juergen Sturm, TUM
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
#
#  * Redistributions of source code must retain the above copyright
#    notice, this list of conditions and the following disclaimer.
#  * Redistributions in binary form must reproduce the above
#    copyright notice, this list of conditions and the following
#    disclaimer in the documentation and/or other materials provided
#    with the distribution.
#  * Neither the name of TUM nor the names of its
#    contributors may be used to endorse or promote products derived
#    from this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
#
# Requirements: 
# sudo apt-get install python-argparse

"""
The Kinect provides the color and depth images in an un-synchronized way. This means that the set of time stamps from the color images do not intersect with those of the depth images. Therefore, we need some way of associating color images to depth images.

For this purpose, you can use the ''associate.py'' script. It reads the time stamps from the rgb.txt file and the depth.txt file, and joins them by finding the best matches.
"""

import argparse
import sys
import os
import numpy


def read_file_list(filename):
    """
    Reads a trajectory from a text file. 
    
    File format:
    The file format is "stamp d1 d2 d3 ...", where stamp denotes the time stamp (to be matched)
    and "d1 d2 d3.." is arbitary data (e.g., a 3D position and 3D orientation) associated to this timestamp. 
    
    Input:
    filename -- File name
    
    Output:
    dict -- dictionary of (stamp,data) tuples
    
    """
    file = open(filename)
    data = file.read()
    lines = data.replace(","," ").replace("\t"," ").split("\n") 
    list = [[v.strip() for v in line.split(" ") if v.strip()!=""] for line in lines if len(line)>0 and line[0]!="#"]
    list = [(float(l[0]),l[1:]) for l in list if len(l)>1]
    return dict(list)

def associate(first_list, second_list,offset,max_difference):
    """
    Associate two dictionaries of (stamp,data). As the time stamps never match exactly, we aim 
    to find the closest match for every input tuple.
    
    Input:
    first_list -- first dictionary of (stamp,data) tuples
    second_list -- second dictionary of (stamp,data) tuples
    offset -- time offset between both dictionaries (e.g., to model the delay between the sensors)
    max_difference -- search radius for candidate generation

    Output:
    matches -- list of matched tuples ((stamp1,data1),(stamp2,data2))
    
    """
    first_keys = first_list.keys()
    second_keys = second_list.keys()
    potential_matches = [(abs(a - (b + offset)), a, b) 
                         for a in first_keys 
                         for b in second_keys 
                         if abs(a - (b + offset)) < max_difference]
    potential_matches.sort()
    matches = []
    for diff, a, b in potential_matches:
        if a in first_keys and b in second_keys:
            first_keys.remove(a)
            second_keys.remove(b)
            matches.append((a, b))
    
    matches.sort()
    return matches

if __name__ == '__main__':
    
    # parse command line
    parser = argparse.ArgumentParser(description='''
    This script takes two data files with timestamps and associates them   
    ''')
    parser.add_argument('first_file', help='first text file (format: timestamp data)')
    parser.add_argument('second_file', help='second text file (format: timestamp data)')
    parser.add_argument('--first_only', help='only output associated lines from first file', action='store_true')
    parser.add_argument('--offset', help='time offset added to the timestamps of the second file (default: 0.0)',default=0.0)
    parser.add_argument('--max_difference', help='maximally allowed time difference for matching entries (default: 0.02)',default=0.02)
    args = parser.parse_args()

    first_list = read_file_list(args.first_file)
    second_list = read_file_list(args.second_file)

    matches = associate(first_list, second_list,float(args.offset),float(args.max_difference))    

    if args.first_only:
        for a,b in matches:
            print("%f %s"%(a," ".join(first_list[a])))
    else:
        for a,b in matches:
            print("%f %s %f %s"%(a," ".join(first_list[a]),b-float(args.offset)," ".join(second_list[b])))
            
        

然后使用命令行进行对齐

python associate.py PATH_TO_SEQUENCE/rgb.txt PATH_TO_SEQUENCE/depth.txt > associations.txt

运行命令行(注意路径问题 以及文件对应问题)

 ./Examples/RGB-D/rgbd_tum Vocabulary/ORBvoc.txt Examples/RGB-D/TUM1.yaml datasets/rgbd_dataset_freiburg1_xyz  datasets/rgbd_dataset_freiburg1_xyz/association.txt 

运行过程:
ORB-SLAM稠密点云地图构建(黑白+彩色)+ pcd文件以八叉树形式表示

保存地图
高博的程序只能实时查看点云地图,不能保存。修改文件 ORB_SLAM2_modified/src/pointcloudmapping.cc,在其中调用 PCL 库的 pcl::io::savePCDFileBinary 函数就可以保存点云地图了。
具体修改如下:
加入头文件

#include <pcl/io/pcd_io.h>

在 void PointCloudMapping::viewer() 函数中( 123 行附近)加入保存地图的命令,最后样式如下:

...
for ( size_t i=lastKeyframeSize; i<N ; i++ )
{
    PointCloud::Ptr p = generatePointCloud( keyframes[i], colorImgs[i], depthImgs[i] );
    *globalMap += *p;
}
pcl::io::savePCDFileBinary("vslam.pcd", *globalMap);   // 只需要加入这一句
...

生成稠密点云地图后保存查看使用pcl_viewer

安装

sudo apt-get install pcl-tools

查看

pcl_viewer vslam.pcd

ORB-SLAM稠密点云地图构建(黑白+彩色)+ pcd文件以八叉树形式表示

上述产生的点云地图为黑白的,接下来进行一些修改使其能生成实时的彩色地图。

彩色

1.在ORB_SLAM2_modified/include/Tracking.h添加

    // Current Frame
    Frame mCurrentFrame;
    cv::Mat mImRGB; //添加这行
    cv::Mat mImGray;
    cv::Mat mImDepth;

2.在ORB_SLAM2_modified/src/Tracking.cc修改2处

cv::Mat Tracking::GrabImageRGBD(const cv::Mat &imRGB,const cv::Mat &imD, const double &timestamp)
{
    mImRGB = imRGB;//添加这行
    mImGray = imRGB;
    mImDepth = imD;

    // insert Key Frame into point cloud viewer
    //mpPointCloudMapping->insertKeyFrame( pKF, this->mImGray, this->mImDepth );
    mpPointCloudMapping->insertKeyFrame( pKF, this->mImRGB, this->mImDepth ); //修改地方

ORB-SLAM稠密点云地图构建(黑白+彩色)+ pcd文件以八叉树形式表示文章来源地址https://www.toymoban.com/news/detail-468644.html

pcd文件以八叉树表示参考这篇教程https://blog.csdn.net/weixin_47185604/article/details/123487506?spm=1001.2014.3001.5506注意命名和文件位置即可

到了这里,关于ORB-SLAM稠密点云地图构建(黑白+彩色)+ pcd文件以八叉树形式表示的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处: 如若内容造成侵权/违法违规/事实不符,请点击违法举报进行投诉反馈,一经查实,立即删除!

领支付宝红包 赞助服务器费用

相关文章

  • 工程(十)——github代码ubuntu20.04在ROS环境运行单目和RGBD相机ORB-SLAM3稠密

    博主创建了一个科研互助群Q:772356582,欢迎大家加入讨论交流一起学习。 加稠密建图:git@github.com:huashu996/ORB_SLAM3_Dense_YOLO.git 纯净版:git@github.com:huashu996/ORB_SLAM3.git orb-slam3的整个环境配置还是比较麻烦的,先将一些坑写在前面,供大家参考和避开这些坑。 orb-slam3的配置要求

    2024年01月25日
    浏览(34)
  • 实测 (四)NVIDIA Xavier NX + D435i / 奥比中光Astrapro 相机+ ORB-SLAM 2 + 3 稠密回环建图

    首先小白老师分享的ORB-SLAM3的可回环的稠密地图版本,具体在这篇博客,下载但是却没有相关的具体实现教程,这里我们先使用 奥比中光Astrapro 两款相机进行配置实现 其实与orb-slam2的环境配置一样,使用的仍然是pagolin0.5,和opencv3.2.0版本(3.4.x也可以),pcl1.8.1+vtk7.1.1 这里

    2024年02月16日
    浏览(34)
  • 实测 (二)NVIDIA Xavier NX + D435i / 奥比中光Astrapro 相机+ ORB-SLAM 2 + 3 稠密回环建图

    接着上篇,开始orb-slam2稠密回环建图 先上效果图  这里感谢大神提供一个可回环的稠密地图版本: https://github.com/xiaobainixi/ORB-SLAM2_RGBD_DENSE_MAP.git 2.1 安装依赖(和orb-slam2环境配置一样,如果已经配置过,可以跳到pcl安装) (1)Pangolin(推荐0.5版本) (2)opencv3.2.0(巨坑!!

    2024年02月08日
    浏览(33)
  • 视觉学习笔记4——ORB-SLAM3的地图保存与使用

    前言:视觉学习笔记4——学习研究ORB-SLAM3 ORB-SLAM3基本搭建完成,具体可以看开头的系列文章目录,接下来需要研究如何自定义自己的地图,也就是实时地图的保存与运用。 按照开源说明来看,地图保存与加载在V1.0已经实现了,需要修改相应的yaml文件即可,也就是相机yaml文

    2024年02月06日
    浏览(37)
  • ORB SLAM3 点云地图保存

    目前 ORB_SLAM3 已经提供了地图保存功能。 方法是在 yaml 文件中以下这行配置: 保存下来的地图可以在下次运行 ORB_SLAM3 时加载。 然而,我经过搜索,没能找到关于 .osa 文件离线加载和可视化的方法,于是对 ORB_SLAM3 的代码进行了简单的修改,使其可以保存 pcd 格式的点云地图

    2024年02月06日
    浏览(52)
  • 【视觉SLAM】ORB-SLAM2S: A Fast ORB-SLAM2 System with Sparse Optical Flow Tracking

    Citations: Y. Diao, R. Cen, F. Xue.ORB-SLAM2S: A Fast ORB-SLAM2 System with Sparse Optical Flow Tracking[C].2021 13th International Conference on Advanced Computational Intelligence (ICACI). Wanzhou,China.2021:160-165. Keywords: Visualization,Simultaneous localization and mapping,Cameras,Real-time systems,Aircraft navigation,Central Processing Unit,Traje

    2023年04月08日
    浏览(50)
  • ORB-SLAM 论文阅读

    论文链接 ORB-SLAM 0. Abstract 本文提出了 ORB-SLAM,一种基于特征的单目同步定位和建图 (SLAM) 系统 该系统对严重的运动杂波具有鲁棒性,允许宽基线环路闭合和重新定位,并包括全自动初始化 选择重建的点和关键帧的适者生存策略具有出色的鲁棒性,并生成紧凑且可跟踪的地图

    2024年01月22日
    浏览(42)
  • SLAM ORB-SLAM2(22)分解基础矩阵

    在 《SLAM ORB-SLAM2(12)估算运动并初始地图点》 中了解到 估算两帧间相对运动过程: 记录特征点对的匹配关系 RANSAC 采样准备 计算H矩阵或者F矩阵 判断并选取模型求位姿过程 在

    2024年04月15日
    浏览(30)
  • 基于ORB-SLAM3库搭建SLAM系统

    博客地址:https://www.cnblogs.com/zylyehuo/ ORB-SLAM3配置及安装教程 ORB-SLAM3配置安装及运行 Win 11pro VMware 17Pro Ubuntu 18.04 Eigen3 Pangolin Opencv3.4.3 ORB-SLAM3源码: https://github.com/UZ-SLAMLab/ORB_SLAM3 安装 Pangolin 需要的依赖工具 安装 Pangolin 官网下载地址:https://opencv.org/releases/page/5/ 下载之后放在

    2024年02月03日
    浏览(36)
  • SLAM ORB-SLAM2(20)查找基础矩阵

    在 《SLAM ORB-SLAM2(12)估算运动并初始地图点》 的 2.3. 计算H矩阵和F矩阵过程 中

    2024年03月17日
    浏览(36)

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

博客赞助

微信扫一扫打赏

请作者喝杯咖啡吧~博客赞助

支付宝扫一扫领取红包,优惠每天领

二维码1

领取红包

二维码2

领红包