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

article/2025/10/23 8:50:05

如有错误,恳请指出。


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

文章目录

  • 1. 数据集准备
  • 2. 环境准备
  • 3. KITTI数据集可视化
  • 4. 点云可视化
  • 5. 鸟瞰图可视化

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.8
conda 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 mlabdataset = kitti_object(os.path.join(ROOT_DIR, '../dataset/KITTI/object'))# determine data_idxdata_idx = 100# Load data from datasetobjects = 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_toptop_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 mlab
from 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_depth
from viz_util import draw_lidar
import cv2
from PIL import Image
import timeclass visualization:# data_idx: determine data_idxdef __init__(self, root_dir=r'E:\Study\Machine Learning\Dataset3d\kitti', data_idx=100):dataset = kitti_object(root_dir=root_dir)# Load data from datasetobjects = 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.shapepc_velo = dataset.get_lidar(data_idx)[:, 0:3]  # 显示bev视图需要改动为[:, 0:4]calib = dataset.get_calibration(data_idx)# init the paramsself.objects = objectsself.img = imgself.img_height = img_heightself.img_width = img_widthself.img_channel = img_channelself.pc_velo = pc_veloself.calib = calib# 1. 图像显示def show_image(self):Image.fromarray(self.img).show()cv2.waitKey(0)# 2. 图片上绘制2D bboxdef show_image_with_2d_boxes(self):show_image_with_boxes(self.img, self.objects, self.calib, show3d=False)cv2.waitKey(0)# 3. 图片上绘制3D bboxdef 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 bboxdef 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_toptop_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 bboxdef 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 np
import mayavi.mlab
import 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 point
y = pointcloud[:, 1]  # y position of point
z = pointcloud[:, 2]  # z position of point
r = pointcloud[:, 3]  # reflectance value of point
d = np.sqrt(x ** 2 + y ** 2)  # Map Distance from sensorvals = 'height'
if vals == "height":col = z
else:col = dfig = mayavi.mlab.figure(bgcolor=(0, 0, 0), size=(640, 500))
mayavi.mlab.points3d(x, y, z,col,  # Values used for Colormode="point",colormap='spectral',  # 'bone', 'copper', 'gnuplot'# color=(0, 1, 0),   # Used a fixed (r,g,b) insteadfigure=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 np
from PIL import Image
import 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.05m
x_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项目


http://chatgpt.dhexx.cn/article/g6g8axNE.shtml

相关文章

KITTI数据集的点云格式转PCD格式

参考文章&#xff1a;https://blog.csdn.net/xinguihu/article/details/78922005 KITTI数据集应该不用多做介绍了&#xff0c;基本上做自动驾驶的都知道这个东西。最近本人用到这个数据集想看看里面的点云长什么模样&#xff0c;却发现有点别扭&#xff0c;没有直接可以看的工…

使用kitti数据集实现自动驾驶——发布照片、点云、IMU、GPS、显示2D和3D侦测框

本次内容主要是使用kitti数据集来可视化kitti车上一些传感器&#xff08;相机、激光雷达、IMU&#xff09;采集的资料以及对行人和车辆进行检测并在图像中画出行人和车辆的2D框、在点云中画出行人和车辆的3D框。 首先先看看最终实现的效果&#xff1a; 自动驾驶视频 看了上面的…

KITTI数据集-label解析笔记

笔记摘自&#xff1a;KITTI数据集--label解析与传感器间坐标转换参数解析_苏源流的博客-CSDN博客 KITTI数据集是自动驾驶领域最知名的数据集之一。 一、kitti数据集&#xff0c;label解析 16个数代表的含义&#xff1a; 第1个字符串&#xff1a;代表目标的类别 Car, Van, Tru…

16个车辆信息检测数据集收集汇总(简介及链接)

16个车辆信息检测数据集收集汇总&#xff08;简介及链接) 转载自&#xff1a;https://blog.csdn.net/u014546828/article/details/109089621?utm_mediumdistribute.pc_relevant.none-task-blog-baidujs_baidulandingword-1&spm1001.2101.3001.4242 目录 1. UA-DETRAC …

双目网络公开数据集的特性

文章目录 概述SceneFlowKITTI 2012 & 2015ETH3D 2017Middlebury 2014 概述 参考文章&#xff1a;Rethinking Training Strategy in Stereo Matching 主流双目公开数据集有&#xff1a;SceneFlow、KITTI、ETH3D、MB。 各个双目网络主流训练数据视差分布的直方图&#xff1a;…

KITTI数据集下载及介绍

KITTI数据集下载及介绍 KITTI数据集由德国卡尔斯鲁厄理工学院和丰田美国技术研究院联合创办&#xff0c;是目前国际上最大的自动驾驶场景下的计算机视觉算法评测数据集。该数据集用于评测立体图像(stereo)&#xff0c;光流(optical flow)&#xff0c;视觉测距(visual odometry…

KITTI 数据集--下载链接

Visual Odometry / SLAM Evaluation 2012 数据集主页&#xff1a;The KITTI Vision Benchmark Suite (cvlibs.net) 里程计基准由22个立体序列组成&#xff0c;以无损失png格式保存。 11个具有真实轨迹的序列&#xff08;00-10&#xff09;用于训练&#xff0c;11个没有真实…

KITTI数据集下载及解析

KITTI数据集下载及解析 W.P. Xiao, Vision group&#xff0c;SHUSV 版本更新时间更新内容作者1V 1.02020.01.09完成主体内容W.P. Xiao2 文章目录 KITTI Dataset1 简介1.1 数据采集平台1.2 坐标系 2 数据解析2.1 image文件2.2 velodyne文件2.3 calib文件2.4 label文件 3 KITTI可…

无人驾驶之KITTI数据集介绍与应用(一)——数据组织方式介绍

本系列博客旨在介绍无人驾驶领域中颇负盛名的KITTI公开数据集&#xff0c;首先整体介绍该数据集的由来、数据组织方式、官方开发工具的使用&#xff0c;重点详细介绍其中对于Object、Tracking和raw data的数据使用&#xff0c;主要分享了我在使用这些数据集时开发的一些工具&am…

waymo数据集总结

参考资料 官网&#xff1a; https://waymo.com/open/data/perception/#lidar-data 文章&#xff1a; https://arxiv.org/pdf/1912.04838.pdf github&#xff1a; https://github.com/waymo-research/waymo-open-dataset colab教程&#xff1a; https://colab.research.google.…

KITTI数据集介绍

目录 1、KITTI数据集概述2、kitti数据采集平台3、Kitti数据集标注格式参考文献&#xff1a; 1、KITTI数据集概述 KITTI数据集由德国卡尔斯鲁厄理工学院和丰田美国技术研究院联合创办&#xff0c;是目前国际上最大的自动驾驶场景下的算法评测数据集。该数据集用于评测立体图像(…

KITTI 数据集简介

数据集简介 KITTI数据集由德国卡尔斯鲁厄理工学院和丰田美国技术研究院联合创办&#xff0c;是目前国际上自动驾驶场景下常用的数据集之一。KITTI数据集的数据采集平台装配有2个灰度摄像机&#xff0c;2个彩色摄像机&#xff0c;一个Velodyne 64线3D激光雷达&#xff0c;4个光…

KITTI数据集简析

文章目录 KITTI数据集数据集结构数据集内容data_object_calib 样本标定数据data_object_label_2 3D点云标注文件 KITTI数据集 数据集结构 KITTI数据集网盘 提取码&#xff1a;0bjl KITTI ├── devkit_object | ├── cpp | ├── mapping | ├── matlab | └─…

KITTI数据集(概念版)

一、参考资料 KITTI 官网 kitti数据集各个榜单介绍 自动驾驶KITTI数据集详解 KITTI数据集简介与使用 kitti数据集各个榜单介绍 KITTI数据集介绍 KITTI数据集简介&#xff08;一&#xff09; — 激光雷达数据 【KITTI】KITTI数据集简介&#xff08;二&#xff09; — 标注数据l…

KITTI数据集

KITTI数据集分为2012和2015 KITTI数据集由德国卡尔斯鲁厄理工学院和丰田美国技术研究院联合创办&#xff0c;是目前国际上最大的自动驾驶场景下的计算机视觉算法评测数据集。KITTI包含市区、乡村和高速公路等场景采集的真实图像数据&#xff0c;每张图像中最多达15辆车和30个行…

Vins-fusion gps融合 KITTY数据集测试

下载kitti数据集 下载kitti数据集和真值poses的00.txt以及sequences文件00序列的times.txt&#xff0c;&#xff08;全网找了好久&#xff0c;最后不得已翻墙从官网down下来的&#xff09; 代码修改&#xff0c;保存输出数据 先指定输出路径:打开vins-fusion/config/kitti_r…

详解KITTI数据集

详解KITTI数据集 一、KITTI数据集发布方 2011年&#xff0c;Andreas Geiger&#xff08;KIT&#xff09;、Philip Lenz&#xff08;KIT&#xff09;、Raquel Urtasun&#xff08;TTIC&#xff09;三位年轻人发现&#xff0c;阻碍视觉感知系统在自动驾驶领域应用的主要原因之一…

KITTI数据集简介与使用

1.KITTI数据集概述 KITTI数据集由德国卡尔斯鲁厄理工学院和丰田美国技术研究院联合创办&#xff0c;是目前国际上最大的自动驾驶场景下的计算机视觉算法评测数据集。该数据集用于评测立体图像(stereo)&#xff0c;光流(optical flow)&#xff0c;视觉测距(visual odometry)&…

计算机视觉数据集介绍:KITTI数据集

KITTI数据集简介 KITTI数据集是由德国卡尔斯鲁厄理工学院和丰田美国技术研究院联合创办&#xff0c;利用组装的设备齐全的采集车辆对实际交通场景进行数据采集获得的公开数据集。该数据集包含丰富多样的传感器数据&#xff08;有双目相机、64线激光雷达、GPS/IMU组合导航定位系…

盘阿里云ECS内挖矿程序

1.二话不说先上图&#xff0c;cpu一路飙升在100% 2.进入服务器top命令查看占用cpu的异常进程 3.找到目标PID kill -9 10478 干掉这个进程&#xff0c;没几秒这个Macron的进程又死灰复燃 4.定位Macron目录 ls -l /proc/$PID/exe 定位到发现目标文件为/tmp/Macron&#xff0c;…