mayavi可视化坐标系pose

本文介绍了如何利用Python中的mayavi库和numpy进行三维位姿可视化,特别是在6D位姿估计任务中。示例代码展示了从./pose目录下读取4x4位姿矩阵txt文件,然后使用mayavi可视化这些位姿及其对应的坐标轴。通过Python脚本,可以快速便捷地完成复杂的3D可视化任务,相比于C++提供了更高的效率。

介绍一个很好用的python可视化库:mayavi,其底层实现是vtk库。
在从事6D位姿估计方面的工作时,经常需要可视化各种坐标系的朝向,而使用C++编写可视化程序比较复杂,而通过python脚本可以快速完成。
下面给出一个可视化pose的程序,作用是从./pose文件夹下读取保存4*4位姿矩阵的一组txt文件可视化位姿,并可视化Oxyz坐标系。

import numpy as np
from mayavi import mlab
from pathlib import Path


poses = Path(r"./pose").glob("*")
for pose_file in poses:
    pose = np.loadtxt(str(pose_file))
    print(pose)

    mlab.quiver3d(pose[0][3], pose[1][3], pose[2][3], pose[0][0], pose[1][0], pose[2][0], line_width=3, scale_factor=100, colormap = "Reds")
    mlab.quiver3d(pose[0][3], pose[1][3], pose[2][3], pose[0][1], pose[1][1], pose[2][1], line_width=3, scale_factor=100, colormap = "Greens")
    mlab.quiver3d(pose[0][3], pose[1][3], pose[2][3], pose[0][2], pose[1][2], pose[2][2], line_width=3, scale_factor=100, colormap = "Blues")

mlab.quiver3d(0, 0, 0, 1, 0, 0, line_width=3, scale_factor=200, colormap = "Reds")
mlab.quiver3d(0, 0, 0, 0, 1, 0, line_width=3, scale_factor=200, colormap = "Greens")
mlab.quiver3d(0, 0, 0, 0, 0, 1, line_width=3, scale_factor=200, colormap = "Blues")

mlab.show()
Mayavi 的参考手册,适合初学者和expert。 User guide: full table of contents An overview of Mayavi Introduction What is Mayavi2? Technical details Using Mayavi as an application, or a library? Scenes, data sources, and visualization modules: the pipeline model Loading data into Mayavi Installation Installing ready-made distributions Requirements for manual installs Doing it yourself: Python packages: Eggs Installing with easy_install Step-by-step instructions to install with eggs under Windows Under Mac OSX Snow Leopard The bleeding edge: Git Testing your installation Troubleshooting Using the Mayavi application Tutorial examples to learn Mayavi Parametric surfaces: a simple introduction to visualization Loading scalar data: the heart.vtk example Visualizing rich datasets: the fire_ug.vtu example Using Mayavi with scipy Exploring a vector field General layout of UI Visualizing data Modules Filters Interaction with the scene Mouse interaction Keyboard interaction From interactive usage to scripting The embedded Python interpreter Recording Mayavi actions to a script Command line arguments mlab: Python scripting for 3D plotting A demo 3D Plotting functions for numpy arrays 0D and 1D data 2D data 3D data Changing the looks of the visual objects created Adding color or size variations Changing the scale and position of objects Changing object properties interactively Figures, legends, camera and decorations Handling several figures Figure decorations Moving the camera Running mlab scripts Using mlab interactively Using together with Matplotlib’s pylab In scripts Animating the data Assembling pipelines with mlab Data sources Modules and filters Case studies of some visualizations Visualizing volumetric scalar data Visualizing a vector field Advanced use of Mayavi Organisation of Mayavi visualizations: the pipeline Anatomy of a Mayavi pipeline The link between different Mayavi entry points A pipeline example examined Data representation in Mayavi Introduction to TVTK datasets The flow of data Retrieving the data from Mayavi pipelines Dissection of the different TVTK datasets Inserting TVTK datasets in the Mayavi pipeline Objects populating the Mayavi pipeline Scene Source Filter ModuleManager: Colors and legends node Module Engine Base class: PipelineBase Class hierarchy Advanced Scripting with Mayavi Design Overview: Mayavi as a visualization framework Scripting the mayavi2 application Using the Mayavi envisage plugins Building applications using Mayavi Custom interactive dialogs Embedding a Mayavi scene in a Traits dialog A scene, with mlab embedded Making the visualization live Integrating in a WxPython application Integrating in a Qt application Tips and Tricks Off screen rendering Avoiding the rendering window Platform Summary Rendering using the virtual framebuffer Using VTK with Mesa for pure software rendering Extending Mayavi with customizations Customizing Mayavi2 Scripting Mayavi without using Envisage Computing in a thread Polling a file and auto-updating Mayavi Serving Mayavi on the network TCP server: the serve_tcp function UDP server: the serve_udp function Animating a visualization Animating a series of images Making movies from a stack of images Scripting from the command line Texture mapping actors Shifting data and plotting Using the UserDefined filter Sharing the same data between scenes Using mlab Using the core Mayavi API Changing the interaction with a scene Accelerating a Mayavi script Miscellaneous Citing Mayavi Getting help Tests for Mayavi Helping out Development quick start Improving the documentation Example gallery Mlab functions gallery Advanced mlab examples Interactive examples Advanced visualization examples Data interaction examples Misc examples MLab reference Plotting functions barchart contour3d contour_surf flow imshow mesh plot3d points3d quiver3d surf triangular_mesh Figure handling functions clf close draw figure gcf savefig screenshot sync_camera Figure decoration functions colorbar scalarbar vectorbar xlabel ylabel zlabel Camera handling functions move pitch roll view yaw Other functions animate axes get_engine orientation_axes outline set_engine show show_engine show_pipeline start_recording stop_recording text text3d title Mlab pipeline-control reference Sources Tools Data Modules and Filters Mayavi API reference Pipeline base objects Scene Source Filter ModuleManager Module PipelineBase Engine Main view and UI objects Scene UIs: DecoratedScene and MayaviScene SceneEditor MlabSceneModel EngineView and EngineRichView Known bugs and issues Changelog Mayavi 3.4.0 (Oct 15, 2010) Enhancements Fixes Mayavi 3.3.2 (May 25, 2010) Enhancements Fixes Mayavi 3.3.1 (Feb 24, 2010) Enhancements Fixes Mayavi 3.3.0 (July 15, 2009) Enhancements Fixes Mayavi 3.2.0 (March 23, 2009) Mayavi 3.1.0 Mayavi 3.0.3 Mayavi 3.0.1 and 3.0.2 Mayavi 3.0.0
### 使用 Mayavi 对 VOD 数据集进行可视化的解决方案 Mayavi 是一个强大的 Python 库,专门用于科学计算中的三维可视化[^1]。为了实现对 VOD 数据集的可视化,可以按照以下方法操作。 #### 安装依赖项 在使用 Mayavi 进行可视化之前,需确保已正确安装所需的软件包。以下是推荐的安装命令: ```bash conda install python=3.6.2 pip install pyqt5==5.15.2 pip install mayavi==4.6.0 ``` 这些命令可以帮助设置适合运行 Mayavi 的环境[^3]。 --- #### 加载并处理 VOD 数据集 假设 VOD 数据集中包含了点云数据或其他形式的空间坐标信息,则可以通过 NumPy 或其他工具加载原始文件,并将其转换为适用于 Mayavi 处理的数据结构。例如,如果数据存储在一个二进制文件中,可采用如下方式读取: ```python import numpy as np # 假设 hgt 文件包含 16 位整数类型的点云数据 with open('path_to_vod_data.hgt', 'rb') as f: data = np.frombuffer(f.read(), dtype='>i2') # 将一维数组重塑成二维矩阵 (以适应具体场景为例调整形状) data = data.reshape((len(data)//8, 8)) print("Data Shape:", data.shape) ``` 上述代码片段展示了如何从 `.hgt` 类型文件中提取空间数据[^2]。对于不同的 VOD 数据格式,可能需要修改解析逻辑。 --- #### 利用 Mayavi 实现三维可视化 一旦完成数据预处理工作,就可以调用 Mayavi 提供的功能绘制三维图形。下面给出一段完整的示例程序: ```python from mayavi import mlab import numpy as np def visualize_vod_dataset(file_path): with open(file_path, 'rb') as f: raw_data = np.frombuffer(f.read(), dtype='>i2') points_count = len(raw_data) // 3 # 每三个数值表示一个点(x,y,z) xyz_points = raw_data[:points_count * 3].reshape(-1, 3) x, y, z = xyz_points[:, 0], xyz_points[:, 1], xyz_points[:, 2] fig = mlab.figure(bgcolor=(1, 1, 1), size=(800, 700)) pts = mlab.points3d( x, y, z, scale_factor=0.1, color=(0, 0, 1), mode="sphere", resolution=20, ) mlab.axes(pts, ranges=[np.min(x), np.max(x), np.min(y), np.max(y), np.min(z), np.max(z)]) mlab.title("VOD Dataset Visualization", height=0.95) mlab.show() if __name__ == "__main__": file_path = "path_to_your_vod_file.hgt" visualize_vod_dataset(file_path) ``` 此脚本定义了一个函数 `visualize_vod_dataset()` 来加载指定路径下的 VOD 数据文件,并通过 Mayavi 创建交互式的三维散点图。注意要替换 `"path_to_your_vod_file.hgt"` 成实际使用的文件位置。 --- #### 结果说明 执行以上代码后会弹出窗口显示由 VOD 数据构成的三维模型。用户可通过鼠标拖拽旋转视角观察细节特征;同时支持缩放和平移等功能提升分析效率。 ---
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

给算法爸爸上香

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值