本文主要是介绍Python plot point cloud and max bounding box of point cloud.,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
# 点云显示
# 外接包围盒显示import os
from matplotlib import pyplot as plt
from mpl_toolkits.mplot3d import Axes3Ddef displayPoint(data):#解决中文显示问题# plt.rcParams['font.sans-serif']=['SimHei']# plt.rcParams['axes.unicode_minus'] = False#散点图参数设置fig=plt.figure() ax=Axes3D(fig) ax.set_title('points') ax.scatter3D(data[0], data[1],data[2], c = 'r', marker = '.') ax.set_xlabel('x') ax.set_ylabel('y') ax.set_zlabel('z') plt.show()def plot_linear_cube(x, y, z, dx, dy, dz, color='red'):fig = plt.figure()ax = Axes3D(fig)xx = [x, x, x+dx, x+dx, x]yy = [y, y+dy, y+dy, y, y]kwargs = {'alpha': 1, 'color': color}ax.plot3D(xx, yy, [z]*5, **kwargs)ax.plot3D(xx, yy, [z+dz]*5, **kwargs)ax.plot3D([x, x], [y, y], [z, z+dz], **kwargs)ax.plot3D([x, x], [y+dy, y+dy], [z, z+dz], **kwargs)ax.plot3D([x+dx, x+dx], [y+dy, y+dy], [z, z+dz], **kwargs)ax.plot3D([x+dx, x+dx], [y, y], [z, z+dz], **kwargs)plt.title('Cube')plt.show()def plot_BBOX_point(data, x, y, z, dx, dy, dz, color='red'):fig=plt.figure() ax=Axes3D(fig) ax.set_title('points&cube') ax.scatter3D(data[0], data[1],data[2], c = 'r', marker = '.') ax.set_xlabel('x') ax.set_ylabel('y') ax.set_zlabel('z') xx = [x, x, x+dx, x+dx, x]yy = [y, y+dy, y+dy, y, y]kwargs = {'alpha': 1, 'color': color}ax.plot3D(xx, yy, [z]*5, **kwargs)ax.plot3D(xx, yy, [z+dz]*5, **kwargs)ax.plot3D([x, x], [y, y], [z, z+dz], **kwargs)ax.plot3D([x, x], [y+dy, y+dy], [z, z+dz], **kwargs)ax.plot3D([x+dx, x+dx], [y+dy, y+dy], [z, z+dz], **kwargs)ax.plot3D([x+dx, x+dx], [y, y], [z, z+dz], **kwargs)plt.show()def main():data = []xlist = []ylist = []zlist = []with open('./test_1_inliers.txt', 'r') as f:lines = f.readlines()for line in lines:x,y,z = [float(i) for i in line.split(' ')]xlist.append(x)ylist.append(y)zlist.append(z)f.close()data.append(xlist)data.append(ylist)data.append(zlist)xmin = min(xlist)xmax = max(xlist)ymin = min(ylist)ymax = max(ylist)zmin = min(zlist)zmax = max(zlist)dx = xmax - xmindy = ymax - ymindz = zmax - zmin# plot_linear_cube(xmin, ymin, zmin, dx, dy, dz, color='red')# displayPoint(data)plot_BBOX_point(data, xmin, ymin, zmin, dx, dy, dz, color='red')if __name__ == '__main__':main()
点云的绘制也可以用python-pcl中的visualization.py。
这篇关于Python plot point cloud and max bounding box of point cloud.的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!