使用open3d来显示点云
单帧显示1:
from open3d.open3d.geometry import PointCloud
from open3d.open3d.utility import Vector3dVector
from open3d.open3d.visualization import draw_geometries
def visualize(pointcloud):
point_cloud = PointCloud()
point_cloud.points = Vector3dVector(pointcloud[:,0:3].reshape(-1,3))
draw_geometries([point_cloud])
单帧显示2:
import open3d as o3d
import os
pcds = os.listdir("/home/user/Documents/reconstruction/0715_file/0806_reconstruction/")
# pcds = [i for i in pcds if i.split(".")[-1] == "pcd"]
pcds.sort()
for pcd in pcds:
print(pcd)
source = o3d.io.read_point_cloud("/home/user/Documents/reconstruction/0715_file/0806_reconstruction/" + pcd) # source 为需要配准的点云
vis = o3d.visualization.Visualizer()
vis.create_window()
# 将两个点云放入visualizer
vis.add_geometry(source)
# vis.add_geometry(target)
vis.get_render_option().point_size = 2
# 让visualizer渲染点云
vis.update_geometry()
vis.poll_events()
vis.update_renderer()
vis.run()
连续帧显示:
import os
import numpy as np
import open3d as o3d
files = os.listdir("0806_reconstruction/")
vis = o3d.visualization.Visualizer()
vis.create_window()
pointcloud = o3d.geometry.PointCloud()
to_reset = True
vis.add_geometry(pointcloud)
for f in files:
pcd = o3d.io.read_point_cloud("0806_reconstruction/" + f) #此处读取的pcd文件,也可读取其他格式的
pcd = np.asarray(pcd.points).reshape((-1, 3))
pointcloud.points = o3d.utility.Vector3dVector(pcd) # 如果使用numpy数组可省略上两行
vis.update_geometry()
if to_reset:
vis.reset_view_point(True)
to_reset = False
vis.poll_events()
vis.update_renderer()
错误情况 1
在有些情况下,open3d会与torch或其他库冲突,只需要将import open3d
放到第一行就可以了.
错误情况 2
如果出现open3d的错误,可以将open3d的版本换成0.8.0. 其他版本貌似会出现函数找不到的情况