播放ply

import os

import numpy as np

import open3d as o3d

import time

import keyboard

#打开文件路径

path='/home/user/pyProject/siren_js3c_semantic/logs/kitti_label_experiment_rec2/'

files = os.listdir(path)

files.sort(key=lambda x:int(x.split('.')[0]))

vis = o3d.visualization.Visualizer()

vis.create_window()

render_option: o3d.visualization.RenderOption = vis.get_render_option()

pointcloud = o3d.geometry.PointCloud()

R=pointcloud.get_rotation_matrix_from_axis_angle(np.array([135,0,0]))  ##旋转角度

translation=np.array([0,0,0])

render_option.point_size = 2

to_reset = True

vis.add_geometry(pointcloud,reset_bounding_box=False)

def callback(self):

keyboard.wait('space')  ##暂时没有用

for f in files:

     pcd = o3d.io.read_point_cloud(path+f) #此处读取的ply文件,也可读取其他格式的

     print(str(path+f))

     print(pcd.get_axis_aligned_bounding_box())

    print(pcd.get_center())

   # o3d.visualization.draw_geometries([pcd])

   points = np.asarray(pcd.points).reshape((-1, 3))

   colors = np.asarray(pcd.colors).reshape((-1, 3))

   pointcloud.points = o3d.utility.Vector3dVector(points)

   pointcloud.colors = o3d.utility.Vector3dVector(colors)

   pointcloud.rotate(R)

   pointcloud.translate(translation,relative=True)

   vis.update_geometry(pointcloud)

    if to_reset:

        vis.reset_view_point(True)

         to_reset = False

   vis.poll_events()

  # vis.register_animation_callback(callback)

   vis.update_renderer()

    time.sleep(0.2)

你可能感兴趣的:(open3d)