1.python代码:
1 import numpy as np
2 import matplotlib.pyplot as plt
3 from mpl_toolkits.mplot3d import Axes3D
4 #f=open('point cloud.txt','r')
5 f=open('11D-zhongxin1-1_RawXYZ_ds_part2.xyz','r')
6 point=f.read()
7 f.close()
8 l1=point.replace('\n',',')
9 l2=l1.split(',')
10 l2.pop()
11 #print(l2)
12 m1=np.array(l2[0:120000])
13 print(len(m1))
14 #m2=m1.reshape(265565,4)
15 m2=m1.reshape(30000,4)
16 print(m2)
17 m3=[]
18 for each in m2:
19 each_line=list(map(lambda x:float(x),each))
20 m3.append(each_line)
21 m4=np.array(m3)
22
23 x=[k[0] for k in m4]
24 y=[k[1] for k in m4]
25 z=[k[2] for k in m4]
26
27 fig=plt.figure(dpi=120)
28 ax=fig.add_subplot(111,projection='3d')
29 plt.title('point cloud')
30 ax.scatter(x,y,z,c='b',marker='.',s=2,linewidth=0,alpha=1,cmap='spectral')
31
32 #ax.set_facecolor((0,0,0))
33 ax.axis('scaled')
34 # ax.xaxis.set_visible(False)
35 # ax.yaxis.set_visible(False)
36 ax.set_xlabel('X Label')
37 ax.set_ylabel('Y Label')
38 ax.set_zlabel('Z Label')
39 plt.show()
2.运行结果如下:
3.点云的数据格式如下(1-15),其中前三列为x,y,z的坐标,我们取用前三列,第四列可以忽略:
658660.61,4231154.24,-13.69,-13.690001
658660.21,4231154.44,-14.12,-14.120000
658660.41,4231154.44,-14.02,-14.025000
658660.61,4231154.44,-14.19,-14.195000
658660.81,4231154.44,-14.13,-14.132500
658661.01,4231154.44,-14.16,-14.160000
658661.21,4231154.44,-13.94,-13.935000
658660.21,4231154.64,-14.07,-14.073333
658660.41,4231154.64,-14.13,-14.127778
658660.61,4231154.64,-14.15,-14.155000
658660.81,4231154.64,-14.06,-14.055000
658661.01,4231154.64,-13.98,-13.977500
658661.21,4231154.64,-13.81,-13.805000
658661.61,4231154.64,-13.94,-13.940000
658660.01,4231154.84,-14.15,-14.150000