iis服务器助手广告广告
返回顶部
首页 > 资讯 > 后端开发 > Python >KITTI数据集可视化(一):点云多种视图的可视化实现
  • 805
分享到

KITTI数据集可视化(一):点云多种视图的可视化实现

自动驾驶python人工智能点云可视化KITTI数据集 2023-09-17 22:09:38 805人浏览 薄情痞子

Python 官方文档:入门教程 => 点击学习

摘要

如有错误,恳请指出。 在本地上,可以安装一些软件,比如:Meshlab,CloudCompare等3D查看工具来对点云进行可视化。而这篇博客是将介绍一些代码工具将KITTI数据集进行可视化操作,包


如有错误,恳请指出。


在本地上,可以安装一些软件,比如:Meshlab,CloudCompare等3D查看工具来对点云进行可视化。而这篇博客是将介绍一些代码工具将KITTI数据集进行可视化操作,包括点云鸟瞰图,FOV图,以及标注信息在图像+点云上的显示。

文章目录

1. 数据集准备

KITTI数据集作为自动驾驶领域的经典数据集之一,比较适合我这样的新手入门。以下资料是为了实现对KITTI数据集的可视化操作。首先在官网下载对应的数据:Http://www.cvlibs.net/datasets/kitti/eval_object.PHP?obj_benchmark=3d,下载后数据的目录文件结构如下所示:

├── dataset│   ├── KITTI│   │   ├── object│   │   │   ├──KITTI│   │   │      ├──ImageSets│   │   │   ├──training│   │   │      ├──calib & velodyne & label_2 & image_2

2. 环境准备

这里使用了一个kitti数据集可视化的开源代码:https://GitHub.com/kuixu/kitti_object_vis,按照以下操作新建一个虚拟环境,并安装所需的工具包。其中千万不要安装python3.7以上的版本,因为vtk不支持。

# 新建python=3.7的虚拟环境conda create -n kitti_vis Python=3.7 # vtk does not support python 3.8conda activate kitti_vis# 安装OpenCV, pillow, scipy, matplotlib工具包pip install opencv-python pillow scipy matplotlib# 安装3D可视化工具包(以下指令会自动安转所需的vtk与pyQt5)conda install mayavi -c conda-forge# 测试python kitti_object.py --show_lidar_with_depth --img_fov --const_box --vis

3. KITTI数据集可视化

下面依次展示 KITTI 数据集可视化结果,这里通过设置 data_idx=10 来展示编号为000010的数据,代码中dataset需要修改为数据集实际路径。(最后会贴上完整代码)

def visualization():    import mayavi.mlab as mlab    dataset = kitti_object(os.path.join(ROOT_DIR, '../dataset/KITTI/object'))        # determine data_idx    data_idx = 100        # Load data from dataset    objects = dataset.get_label_objects(data_idx)     print("There are %d objects.", len(objects))    img = dataset.get_image(data_idx)                 img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)    img_height, img_width, img_channel = img.shape     pc_velo = dataset.get_lidar(data_idx)[:,0:3]      calib = dataset.get_calibration(data_idx)   

代码来源于参考资料,在后面会贴上我自己修改的测试代码。以下包含9种可视化的操作:

  • 1. 图像显示
def show_image(self):    Image.fromarray(self.img).show()    cv2.waiTKEy(0)

结果展示:

在这里插入图片描述

  • 2. 图片上绘制2D bbox
    def show_image_with_2d_boxes(self):        show_image_with_boxes(self.img, self.objects, self.calib, show3d=False)        cv2.waitKey(0)

结果展示:

在这里插入图片描述

  • 3. 图片上绘制3D bbox
    def show_image_with_3d_boxes(self):        show_image_with_boxes(self.img, self.objects, self.calib, show3d=True)        cv2.waitKey(0)

结果展示:

在这里插入图片描述

  • 4. 图片上绘制Lidar投影
    def show_image_with_lidar(self):        show_lidar_on_image(self.pc_velo, self.img, self.calib, self.img_width, self.img_height)        mlab.show()

结果展示:

在这里插入图片描述

  • 5. Lidar绘制3D bbox
    def show_lidar_with_3d_boxes(self):        show_lidar_with_boxes(self.pc_velo, self.objects, self.calib, True, self.img_width, self.img_height)        mlab.show()

结果展示:

在这里插入图片描述

  • 6. Lidar绘制FOV图
    def show_lidar_with_fov(self):        imgfov_pc_velo, pts_2d, fov_inds = get_lidar_in_image_fov(self.pc_velo, self.calib,          0, 0, self.img_width, self.img_height, True)        draw_lidar(imgfov_pc_velo)        mlab.show()

结果展示:

在这里插入图片描述

  • 7. Lidar绘制3D图
    def show_lidar_with_3dview(self):        draw_lidar(self.pc_velo)        mlab.show()

结果展示:

在这里插入图片描述

  • 8. Lidar绘制BEV图

BEV图的显示与其他视图不一样,这里的代码需要有点改动,因为这里需要lidar点云的其他维度信息,所以输入不仅仅是xyz三个维度。改动代码:

# 初始pc_velo = dataset.get_lidar(data_idx)[:, 0:3]# 改为(要增加其他维度才可以查看BEV视图)pc_velo = dataset.get_lidar(data_idx)[:, 0:4]

测试代码:

    def show_lidar_with_bev(self):        from kitti_util import draw_top_image, lidar_to_top        top_view = lidar_to_top(self.pc_velo)        top_image = draw_top_image(top_view)        cv2.imshow("top_image", top_image)        cv2.waitKey(0)

结果展示:

在这里插入图片描述

  • 9. Lidar绘制BEV图+2D bbox

同样,这里的代码改动与3.8节一样,需要点云的其他维度信息

    def show_lidar_with_bev_2d_bbox(self):        show_lidar_topview_with_boxes(self.pc_velo, self.objects, self.calib)        mlab.show()

结果展示:

在这里插入图片描述

  • 完整测试代码

参考代码:

import mayavi.mlab as mlabfrom kitti_object import kitti_object, show_image_with_boxes, show_lidar_on_image, \    show_lidar_with_boxes, show_lidar_topview_with_boxes, get_lidar_in_image_fov, \    show_lidar_with_depthfrom viz_util import draw_lidarimport cv2from PIL import Imageimport timeclass visualization:    # data_idx: determine data_idx    def __init__(self, root_dir=r'E:\Study\Machine Learning\Dataset3d\kitti', data_idx=100):        dataset = kitti_object(root_dir=root_dir)        # Load data from dataset        objects = dataset.get_label_objects(data_idx)        print("There are {} objects.".fORMat(len(objects)))        img = dataset.get_image(data_idx)        img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)        img_height, img_width, img_channel = img.shape        pc_velo = dataset.get_lidar(data_idx)[:, 0:3]  # 显示bev视图需要改动为[:, 0:4]        calib = dataset.get_calibration(data_idx)        # init the params        self.objects = objects        self.img = img        self.img_height = img_height        self.img_width = img_width        self.img_channel = img_channel        self.pc_velo = pc_velo        self.calib = calib    # 1. 图像显示    def show_image(self):        Image.fromarray(self.img).show()        cv2.waitKey(0)    # 2. 图片上绘制2D bbox    def show_image_with_2d_boxes(self):        show_image_with_boxes(self.img, self.objects, self.calib, show3d=False)        cv2.waitKey(0)    # 3. 图片上绘制3D bbox    def show_image_with_3d_boxes(self):        show_image_with_boxes(self.img, self.objects, self.calib, show3d=True)        cv2.waitKey(0)    # 4. 图片上绘制Lidar投影    def show_image_with_lidar(self):        show_lidar_on_image(self.pc_velo, self.img, self.calib, self.img_width, self.img_height)        mlab.show()    # 5. Lidar绘制3D bbox    def show_lidar_with_3d_boxes(self):        show_lidar_with_boxes(self.pc_velo, self.objects, self.calib, True, self.img_width, self.img_height)        mlab.show()    # 6. Lidar绘制FOV图    def show_lidar_with_fov(self):        imgfov_pc_velo, pts_2d, fov_inds = get_lidar_in_image_fov(self.pc_velo, self.calib,          0, 0, self.img_width, self.img_height, True)        draw_lidar(imgfov_pc_velo)        mlab.show()    # 7. Lidar绘制3D图    def show_lidar_with_3dview(self):        draw_lidar(self.pc_velo)        mlab.show()    # 8. Lidar绘制BEV图    def show_lidar_with_bev(self):        from kitti_util import draw_top_image, lidar_to_top        top_view = lidar_to_top(self.pc_velo)        top_image = draw_top_image(top_view)        cv2.imshow("top_image", top_image)        cv2.waitKey(0)    # 9. Lidar绘制BEV图+2D bbox    def show_lidar_with_bev_2d_bbox(self):        show_lidar_topview_with_boxes(self.pc_velo, self.objects, self.calib)        mlab.show()if __name__ == '__main__':    kitti_vis = visualization()    # kitti_vis.show_image()    # kitti_vis.show_image_with_2d_boxes()    # kitti_vis.show_image_with_3d_boxes()    # kitti_vis.show_image_with_lidar()    # kitti_vis.show_lidar_with_3d_boxes()    # kitti_vis.show_lidar_with_fov()    # kitti_vis.show_lidar_with_3dview()    # kitti_vis.show_lidar_with_bev()    kitti_vis.show_lidar_with_bev_2d_bbox()    # print('...')    # cv2.waitKey(0)

此外,下面再提供两份可视化代码。


4. 点云可视化

这里的同样使用的是上述的图例,且直接输入的KITTI数据集的.bin文件,即可显示点云图像。

  • 参考代码:
import numpy as npimport mayavi.mlabimport os# 000010.bin这里需要填写文件的位置# bin_file = '../data/object/training/velodyne/000000.bin'# assert os.path.exists(bin_file), "{} is not exists".format(bin_file)kitti_file = r'E:\Study\Machine Learning\Dataset3d\kitti\training\velodyne\000100.bin'pointcloud = np.fromfile(file=kitti_file, dtype=np.float32, count=-1).reshape([-1, 4])# pointcloud = np.fromfile(str("000010.bin"), dtype=np.float32, count=-1).reshape([-1, 4])print(pointcloud.shape)x = pointcloud[:, 0]  # x position of pointy = pointcloud[:, 1]  # y position of pointz = pointcloud[:, 2]  # z position of pointr = pointcloud[:, 3]  # reflectance value of pointd = np.sqrt(x ** 2 + y ** 2)  # Map Distance from sensorvals = 'height'if vals == "height":    col = zelse:    col = dfig = mayavi.mlab.figure(bGColor=(0, 0, 0), size=(640, 500))mayavi.mlab.points3d(x, y, z,                     col,  # Values used for Color                     mode="point",                     colormap='spectral',  # 'bone', 'copper', 'gnuplot'                     # color=(0, 1, 0),   # Used a fixed (r,g,b) instead                     figure=fig,                     )x = np.linspace(5, 5, 50)y = np.linspace(0, 0, 50)z = np.linspace(0, 5, 50)mayavi.mlab.plot3d(x, y, z)mayavi.mlab.show()
  • 输出结果:

在这里插入图片描述

ps:这里的输出点云结果相比上面的点云输出结果更加的完善,而且参考的中心坐标点也不一样。


5. 鸟瞰图可视化

代码中的鸟瞰图范围可以自行设置。同样,输入的也只需要是.bin文件即可展示其鸟瞰图。

  • 参考代码:
import numpy as npfrom PIL import Imageimport matplotlib.pyplot as plt# 点云读取:000010.bin这里需要填写文件的位置kitti_file = r'E:\Study\Machine Learning\Dataset3d\kitti\training\velodyne\000100.bin'pointcloud = np.fromfile(file=kitti_file, dtype=np.float32, count=-1).reshape([-1, 4])# 设置鸟瞰图范围side_range = (-40, 40)  # 左右距离# fwd_range = (0, 70.4)  # 后前距离fwd_range = (-70.4, 70.4)x_points = pointcloud[:, 0]y_points = pointcloud[:, 1]z_points = pointcloud[:, 2]# 获得区域内的点f_filt = np.logical_and(x_points > fwd_range[0], x_points < fwd_range[1])s_filt = np.logical_and(y_points > side_range[0], y_points < side_range[1])filter = np.logical_and(f_filt, s_filt)indices = np.argwhere(filter).flatten()x_points = x_points[indices]y_points = y_points[indices]z_points = z_points[indices]res = 0.1  # 分辨率0.05mx_img = (-y_points / res).astype(np.int32)y_img = (-x_points / res).astype(np.int32)# 调整坐标原点x_img -= int(np.floor(side_range[0]) / res)y_img += int(np.floor(fwd_range[1]) / res)print(x_img.min(), x_img.max(), y_img.min(), x_img.max())# 填充像素值height_range = (-2, 0.5)pixel_value = np.clip(a=z_points, a_max=height_range[1], a_min=height_range[0])def scale_to_255(a, min, max, dtype=np.uint8):    return ((a - min) / float(max - min) * 255).astype(dtype)pixel_value = scale_to_255(pixel_value, height_range[0], height_range[1])# 创建图像数组x_max = 1 + int((side_range[1] - side_range[0]) / res)y_max = 1 + int((fwd_range[1] - fwd_range[0]) / res)im = np.zeros([y_max, x_max], dtype=np.uint8)im[y_img, x_img] = pixel_value# imshow (灰度)im2 = Image.fromarray(im)im2.show()# imshow (彩色)# plt.imshow(im, cmap="nipy_spectral", vmin=0, vmax=255)# plt.show()
  • 结果展示:

在这里插入图片描述
后续的工作会加深对点云数据的理解,整个可视化项目的工程见:KITTI数据集的可视化项目,有需要的朋友可以自行下载。


参考资料:

1. KITTI自动驾驶数据集可视化教程

2. kitti数据集在3D目标检测中的入门

3. kitti数据集在3D目标检测中的入门(二)可视化详解

4. kitti_object_vis项目

来源地址:https://blog.csdn.net/weixin_44751294/article/details/127345052

--结束END--

本文标题: KITTI数据集可视化(一):点云多种视图的可视化实现

本文链接: https://www.lsjlt.com/news/411397.html(转载时请注明来源链接)

有问题或投稿请发送至: 邮箱/279061341@qq.com    QQ/279061341

本篇文章演示代码以及资料文档资料下载

下载Word文档到电脑,方便收藏和打印~

下载Word文档
猜你喜欢
  • KITTI数据集可视化(一):点云多种视图的可视化实现
    如有错误,恳请指出。 在本地上,可以安装一些软件,比如:Meshlab,CloudCompare等3D查看工具来对点云进行可视化。而这篇博客是将介绍一些代码工具将KITTI数据集进行可视化操作,包...
    99+
    2023-09-17
    自动驾驶 python 人工智能 点云可视化 KITTI数据集
  • pyecharts实现数据可视化
    目录1.概述2.安装3.数据可视化代码3.1 柱状图3.2 折线图3.3 饼图1.概述 pyecharts 是百度开源的,适用于数据可视化的工具,配置灵活,展示图表相对美观,顺滑。 ...
    99+
    2024-04-02
  • PHP与数据可视化的集成
    随着数据分析和流程自动化的需求不断增加,数据可视化已经成为了商业应用和数据分析领域的必需工具。同时,PHP作为一种强大的Web开发语言,在与数据可视化工具的集成方面也备受关注。本文将介绍如何在PHP应用中集成数据可视化工具,为您提供一些有用...
    99+
    2023-05-15
    集成 PHP 数据可视化
  • python用pyecharts实现地图数据可视化
    目录一、全国各省单年GDP的可视化二、全国各省多年GDP的可视化有的时候,我们需要对不同国家或地区的某项指标进行比较,可简单通过直方图加以比较。但直方图在视觉上并不能很好突出地区间的...
    99+
    2024-04-02
  • Python 数据可视化实现5种炫酷的动态图
    本文将介绍 5 种基于 Plotly 的可视化方法,你会发现,原来可视化不仅可用直方图和箱形图,还能做得如此动态好看甚至可交互。 那么,Plotly 有哪些好处?Plotly 的整合...
    99+
    2024-04-02
  • pyecharts如何实现数据可视化
    这篇文章将为大家详细讲解有关pyecharts如何实现数据可视化,小编觉得挺实用的,因此分享给大家做个参考,希望大家阅读完这篇文章后可以有所收获。1.概述pyecharts 是百度开源的,适用于数据可视化的工具,配置灵活,展示图表相对美观,...
    99+
    2023-06-29
  • 怎么实现数据库的可视化
    要实现数据库的可视化,可以使用数据库管理工具或者图形化界面来操作和管理数据库。以下是一些常用的方法:1. 使用数据库管理工具:常见的...
    99+
    2023-08-31
    数据库
  • Django展示可视化图表的多种方式
    目录1. 前言 2. Echarts 3. Pyecharts 3-1  安装依赖3-2  拷贝 pyecharts 的模板文件到项...
    99+
    2024-04-02
  • Pytorch可视化的几种实现方法
    目录一,利用 tensorboardX 可视化网络结构二,利用 vistom 可视化三,利用pytorchviz可视化网络结构一,利用 tensorboardX 可视化网络结构 参...
    99+
    2024-04-02
  • python数据分析绘图可视化
    前言: 数据分析初始阶段,通常都要进行可视化处理。数据可视化旨在直观展示信息的分析结果和构思,令某些抽象数据具象化,这些抽象数据包括数据测量单位的性质或数量。本章用的程序库matpl...
    99+
    2024-04-02
  • Python matplotlib数据可视化图绘制
    目录前言1.折线图2.直方图3.箱线图4.柱状图5.饼图6.散点图前言 导入绘图库: import matplotlib.pyplot as plt import numpy as ...
    99+
    2024-04-02
  • Python数据可视化之环形图
    目录1.引言2.方式一:饼图形式3.方式二:条形图形式1.引言 环形图(圆环)在功能上与饼图相同,整个环被分成不同的部分,用各个圆弧来表示每个数据所占的比例值。但其中心的空白可用于显...
    99+
    2024-04-02
  • Python Matplotlib数据可视化绘图之(三)————散点图
    文章目录 前言一、所用到的模块二、单一颜色的普通不分组散点图1.示例数据如下2.代码如下2.1 代码如下(示例):2.1.1 Case1: 三、多种颜色的普通不分组散点图1....
    99+
    2023-10-26
    matplotlib python 开发语言 pycharm numpy
  • RiSearch PHP 与数据可视化的集成实现方法
    引言:随着互联网的发展,大数据时代已经来临。数据分析和可视化成为了当今企业发展中至关重要的一环。为了更好地分析和可视化数据,很多程序员选择使用RiSearch PHP作为搜索引擎,并通过集成实现数据可视化。本文将详细介绍RiSearch P...
    99+
    2023-10-21
    数据可视化 PHP(编程语言) RiSearch(搜索引擎)
  • Python数据可视化绘图实例详解
    目录利用可视化探索图表1.数据可视化与探索图2.常见的图表实例数据探索实战分享1.2013年美国社区调查2.波士顿房屋数据集利用可视化探索图表 1.数据可视化与探索图 数据可视化是指...
    99+
    2024-04-02
  • Python中怎么实现数据可视化
    这期内容当中小编将会给大家带来有关Python中怎么实现数据可视化,文章内容丰富且以专业的角度为大家分析和叙述,阅读完这篇文章希望大家可以有所收获。1.成品图这个是监控服务器网速的***成果,显示的是下载与上传的网速,单位为M。爬虫的原理都...
    99+
    2023-06-17
  • Vue引入highCharts实现数据可视化
    本文实例为大家分享了Vue引入highCharts实现数据可视化的具体代码,供大家参考,具体内容如下 效果图 文档Api地址 安装 npm install highcharts-v...
    99+
    2024-04-02
  • Echarts中怎么实现数据可视化
    这期内容当中小编将会给大家带来有关Echarts中怎么实现数据可视化,文章内容丰富且以专业的角度为大家分析和叙述,阅读完这篇文章希望大家可以有所收获。Echarts这个方案从我接触到做出一个还算不错的图,也就不过几个小时的时间,其中至少60...
    99+
    2023-06-04
  • Python中如何实现数据可视化
    今天就跟大家聊聊有关Python中如何实现数据可视化,可能很多人都不太了解,为了让大家更加了解,小编给大家总结了以下内容,希望大家根据这篇文章可以有所收获。热力图热力图(Heat Map)是数据的一种矩阵表示方法,其中每个矩阵元素的值通过一...
    99+
    2023-06-16
  • python flask数据可视化怎么实现
    这篇文章主要介绍了python flask数据可视化怎么实现的相关知识,内容详细易懂,操作简单快捷,具有一定借鉴价值,相信大家阅读完这篇python flask数据可视化怎么实现文章都会有所收获,下面我们一...
    99+
    2024-04-02
软考高级职称资格查询
编程网,编程工程师的家园,是目前国内优秀的开源技术社区之一,形成了由开源软件库、代码分享、资讯、协作翻译、讨论区和博客等几大频道内容,为IT开发者提供了一个发现、使用、并交流开源技术的平台。
  • 官方手机版

  • 微信公众号

  • 商务合作