点云数据集可视化

ModelNet40数据集可视化:


import open3d as o3d
import numpy as np
from plyfile import PlyData
from PIL import Image


# 读取 PLY 文件内容
def read_ply_file(file_path):
    try:
        ply_data = PlyData.read(file_path)
        print("PLY 文件内容成功读取")
        return ply_data
    except Exception as e:
        print(f"读取 PLY 文件时出错: {e}")
        return None


# 将 PlyData 转换为 Open3D 的点云数据结构
def convert_to_open3d_point_cloud(ply_data):
    if ply_data:
        vertex_data = ply_data['vertex'].data
        points = np.array([vertex_data['x'], vertex_data['y'], vertex_data['z']]).T
        point_cloud = o3d.geometry.PointCloud()
        point_cloud.points = o3d.utility.Vector3dVector(points)
        return point_cloud
    else:
        return None


# 将点云绕 x, y, z 轴旋转
def rotate_point_cloud(point_cloud, angle_x, angle_y, angle_z):
    R_x = np.array([
        [1, 0, 0],
        [0, np.cos(angle_x), -np.sin(angle_x)],
        [0, np.sin(angle_x), np.cos(angle_x)]
    ])

    R_y = np.array([
        [np.cos(angle_y), 0, np.sin(angle_y)],
        [0, 1, 0],
        [-np.sin(angle_y), 0, np.cos(angle_y)]
    ])

    R_z = np.array([
        [np.cos(angle_z), -np.sin(angle_z), 0],
        [np.sin(angle_z), np.cos(angle_z), 0],
        [0, 0, 1]
    ])

    R = R_z @ R_y @ R_x
    points = np.asarray(point_cloud.points)
    rotated_points = points @ R.T
    point_cloud.points = o3d.utility.Vector3dVector(rotated_points)


# 可视化点云数据并保存当前视角图片
def visualize_and_save_point_cloud(point_cloud, save_path):
    if point_cloud:
        vis = o3d.visualization.Visualizer()
        vis.create_window()
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值