mayavi 显示点云 检测结果

2024-01-17 16:04
文章标签 显示 检测 点云 mayavi

本文主要是介绍mayavi 显示点云 检测结果,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

目录

可视化代码:


mayavi 显示点云 检测结果

输入文件格式是hdf5

字段:

f = h5py.File(args.filename, 'r')
pcls = f['point_cloud']
lidar_pose = f['lidar_pose']
vbbs = f['vehicle_boundingbox']
pbbs = f['pedestrian_boundingbox']

可视化代码:

import argparse
import numpy as np
import h5py
from mayavi import mlabdef getTransform(x, y, z, pitch, yaw, roll, degrees=True):'''Given location x,y,z and pitch, yaw, roll, obtain the matrix that convert from local to global CS using the left-handed system from UE4'''if degrees:pitch, yaw, roll = [np.radians(x) for x in [pitch, yaw, roll]]cy,sy = np.cos(yaw), np.sin(yaw)cr,sr = np.cos(roll), np.sin(roll)cp,sp = np.cos(pitch), np.sin(pitch)mat = np.array([cp * cy, cy * sp * sr - sy * cr, -cy * sp * cr - sy * sr, x, \cp * sy, sy * sp * sr + cy * cr, -sy * sp * cr + cy * sr, y, \sp,               -cp * sr,                 cp * cr, z, \0,                      0,                       0, 1], dtype=np.float).reshape(4,4)return matdef transformPoints(transformMatrix, pts, inverse=False):'''Given a transformation matrix [4,4] convert pts [N,3] or [N,4] (last coordinate is intensity)'''#Check if intensity is availableif pts.shape[1] == 4:#split intensity from 3D coordinates, add homogeneus coordinateintensity = pts[:,-1,np.newaxis].copy()pts[:,-1] = 1else:#add homogeneus coordinateintensity = Nonepts = np.concatenate([pts, np.ones((pts.shape[0],1))], axis=1)#perform transformationmat = np.array(transformMatrix)if inverse:mat = np.linalg.inv(mat)ptst = pts @ mat.Tptst = ptst[:,:3]#merge intensity backif intensity is not None:ptst = np.concatenate([ptst,intensity], axis=1)return ptstdef updateBoundingBox(x,y,z,yaw,pitch,w,l,h, vis_bb):#Create 8 corner pointscpts = 0.5*np.array([[-1,1,-1],[1,1,-1],[1,-1,-1],[-1,-1,-1],[-1,1,1],[1,1,1],[1,-1,1],[-1,-1,1]])cpts *= np.array([[w,l,h]])cpts = transformPoints(getTransform(x,y,z,pitch,yaw,0), cpts)#list of 16 points to create whole BBpts = cpts[[0,3,7,3,2,6,2,1,5,1,0,4,7,6,5,4],:]#update visvis_bb.mlab_source.reset(x=pts[:,0], y=pts[:,1], z=pts[:,2])def main(args):#Load file/dataf = h5py.File(args.filename, 'r')pcls = f['point_cloud']lidar_pose = f['lidar_pose']vbbs = f['vehicle_boundingbox']pbbs = f['pedestrian_boundingbox']nframes = pcls.shape[0]nvehicles = pcls.shape[1]npedestrians = pbbs.shape[1]#Create Mayavi Visualisationfig = mlab.figure(size=(960,540), bgcolor=(0.05,0.05,0.05))zeros = np.zeros(pcls.shape[1]*pcls.shape[2])vis = mlab.points3d(zeros, zeros, zeros, zeros, mode='point', figure=fig)zeros = np.zeros(16)vis_vbbs = [mlab.plot3d(zeros, zeros, zeros, zeros, color=(0,1,0), tube_radius=None, line_width=1, figure=fig) for i in range(nvehicles)]vis_pbbs = [mlab.plot3d(zeros, zeros, zeros, zeros, color=(0,1,1), tube_radius=None, line_width=1, figure=fig) for i in range(npedestrians)]#Iterate through frames@mlab.animate(delay=100)def anim():for frame in range(nframes):print(f'Frame {frame}')#Update pedestrian bounding boxesfor i in range(npedestrians):updateBoundingBox(*pbbs[frame, i].tolist(), vis_pbbs[i])fusedPCL = []for i in range(nvehicles):#Get PCL for the given vehicle in the global Coordinate Systempcl = pcls[frame,i]transform = getTransform(*lidar_pose[frame,i].tolist())pcl_global = transformPoints(transform, pcl)fusedPCL.append(pcl_global)#Update the vehicle BB visualisationupdateBoundingBox(*vbbs[frame,i].tolist(), vis_vbbs[i])#Update PCL visualisation with MayavifusedPCL = np.concatenate(fusedPCL, axis=0)vis.mlab_source.set(x=fusedPCL[:,0], y=fusedPCL[:,1], z=fusedPCL[:,2], scalars=fusedPCL[:,3])#Set top-view if first frameif frame == 0:mlab.gcf().scene.z_plus_view()yieldanim()mlab.show()if __name__ == '__main__':argparser = argparse.ArgumentParser()argparser.add_argument('filename',type=str,help='Path to snippet to be visualised')args = argparser.parse_args()try:main(args)except KeyboardInterrupt:passfinally:print('Finished visualisation!')

这篇关于mayavi 显示点云 检测结果的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/616538

相关文章

OpenCV实现实时颜色检测的示例

《OpenCV实现实时颜色检测的示例》本文主要介绍了OpenCV实现实时颜色检测的示例,通过HSV色彩空间转换和色调范围判断实现红黄绿蓝颜色检测,包含视频捕捉、区域标记、颜色分析等功能,具有一定的参考... 目录一、引言二、系统概述三、代码解析1. 导入库2. 颜色识别函数3. 主程序循环四、HSV色彩空间

RedisTemplate默认序列化方式显示中文乱码的解决

《RedisTemplate默认序列化方式显示中文乱码的解决》本文主要介绍了SpringDataRedis默认使用JdkSerializationRedisSerializer导致数据乱码,文中通过示... 目录1. 问题原因2. 解决方案3. 配置类示例4. 配置说明5. 使用示例6. 验证存储结果7.

idea中project的显示问题及解决

《idea中project的显示问题及解决》:本文主要介绍idea中project的显示问题及解决方案,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录idea中project的显示问题清除配置重China编程新生成配置总结idea中project的显示问题新建空的pr

电脑显示mfc100u.dll丢失怎么办?系统报错mfc90u.dll丢失5种修复方案

《电脑显示mfc100u.dll丢失怎么办?系统报错mfc90u.dll丢失5种修复方案》最近有不少兄弟反映,电脑突然弹出“mfc100u.dll已加载,但找不到入口点”的错误提示,导致一些程序无法正... 在计算机使用过程中,我们经常会遇到一些错误提示,其中最常见的就是“找不到指定的模块”或“缺少某个DL

使用Python实现IP地址和端口状态检测与监控

《使用Python实现IP地址和端口状态检测与监控》在网络运维和服务器管理中,IP地址和端口的可用性监控是保障业务连续性的基础需求,本文将带你用Python从零打造一个高可用IP监控系统,感兴趣的小伙... 目录概述:为什么需要IP监控系统使用步骤说明1. 环境准备2. 系统部署3. 核心功能配置系统效果展

Linux虚拟机不显示IP地址的解决方法(亲测有效)

《Linux虚拟机不显示IP地址的解决方法(亲测有效)》本文主要介绍了通过VMware新装的Linux系统没有IP地址的解决方法,主要步骤包括:关闭虚拟机、打开VM虚拟网络编辑器、还原VMnet8或修... 目录前言步骤0.问题情况1.关闭虚拟机2.China编程打开VM虚拟网络编辑器3.1 方法一:点击还原VM

CSS模拟 html 的 title 属性(鼠标悬浮显示提示文字效果)

《CSS模拟html的title属性(鼠标悬浮显示提示文字效果)》:本文主要介绍了如何使用CSS模拟HTML的title属性,通过鼠标悬浮显示提示文字效果,通过设置`.tipBox`和`.tipBox.tipContent`的样式,实现了提示内容的隐藏和显示,详细内容请阅读本文,希望能对你有所帮助... 效

Python如何实现PDF隐私信息检测

《Python如何实现PDF隐私信息检测》随着越来越多的个人信息以电子形式存储和传输,确保这些信息的安全至关重要,本文将介绍如何使用Python检测PDF文件中的隐私信息,需要的可以参考下... 目录项目背景技术栈代码解析功能说明运行结php果在当今,数据隐私保护变得尤为重要。随着越来越多的个人信息以电子形

如何设置vim永久显示行号

《如何设置vim永久显示行号》在Linux环境下,vim默认不显示行号,这在程序编译出错时定位错误语句非常不便,通过修改vim配置文件vimrc,可以在每次打开vim时永久显示行号... 目录设置vim永久显示行号1.临时显示行号2.永www.chinasem.cn久显示行号总结设置vim永久显示行号在li

SpringBoot使用Apache Tika检测敏感信息

《SpringBoot使用ApacheTika检测敏感信息》ApacheTika是一个功能强大的内容分析工具,它能够从多种文件格式中提取文本、元数据以及其他结构化信息,下面我们来看看如何使用Ap... 目录Tika 主要特性1. 多格式支持2. 自动文件类型检测3. 文本和元数据提取4. 支持 OCR(光学