资讯动态

【点云】python: 关于点云的一些基本处理

发布时间:2026/10/22 1:01:19 来源:尧图企业网站定制
这些可以作为点云处理的一些函数,LZ在此归纳了一下, 当然matlab或者c版本也都行,最近在用Python,就用Python写的.通常拿到一个mesh或者一些立体数据,存在的模式可能是点云,体素,可能是.off, .ply, .txt各种形式其实是可以相互转换的.下面举个例子# 我们先随机生成一些数字,作为点云输入,为了减少物体尺度的问题,#通常会将点云缩到半径为1的球体中#为了方便起见,LZ把batch_size改成1point_cloudnp.random.rand(1,1024,3)-np.random.rand(1,1024,3)#画出3d点云defpyplot_draw_point_cloud(points,output_filenameNone): points is a Nx3 numpy array figplt.figure()# ax fig.add_subplot(111, projection3d)axAxes3D(fig)ax.scatter(points[:,0],points[:,1],points[:,2])ax.set_xlabel(x)ax.set_ylabel(y)ax.set_zlabel(z)plt.show()# savefig(output_filename)上图为我们随机生成的点云,好吧,完全看不出来什么呢!将点云进行体素化,通常我们处理的点云都是一批一批处理,所以这里写了两个接口,分别针对单个点云和多组点云defpoint_cloud_to_volume_batch(point_clouds,vsize32,radius1.0,flattenTrue): Input is BxNx3 batch of point cloud Output is Bx(vsize^3) vol_list[]forbinrange(point_clouds.shape[0]):volpoint_cloud_to_volume(np.squeeze(point_clouds[b,:,:]),vsize,radius)ifflatten:vol_list.append(vol.flatten())else:vol_list.append(np.expand_dims(np.expand_dims(vol,-1),0))ifflatten:returnnp.vstack(vol_list)else:returnnp.concatenate(vol_list,0)defpoint_cloud_to_volume(points,vsize,radius1.0): input is Nx3 points. output is vsize*vsize*vsize assumes points are in range [-radius, radius] volnp.zeros((vsize,vsize,vsize))voxel2*radius/float(vsize)print(voxel: ,voxel)locations(pointsradius)/voxelprint(locations: ,locations)locationslocations.astype(int)print(locations: ,locations)vol[locations[:,0],locations[:,1],locations[:,2]]1.0returnvol下面两个函数是体素转换成点云,和画出体素的操作:defvolume_to_point_cloud(vol): vol is occupancy grid (value 0 or 1) of size vsize*vsize*vsize return Nx3 numpy array. vsizevol.shape[0]assert(vol.shape[1]vsizeandvol.shape[1]vsize)points[]forainrange(vsize):forbinrange(vsize):forcinrange(vsize):ifvol[a,b,c]1:points.append(np.array([a,b,c]))iflen(points)0:returnnp.zeros((0,3))pointsnp.vstack(points)returnpointsdefpyplot_draw_volume(vol,output_filenameNone): vol is of size vsize*vsize*vsize output an image to output_filename pointsvolume_to_point_cloud(vol)pyplot_draw_point_cloud(points,output_filename)这个角度好像看不清楚,那么我们换个角度来看下:哈哈,Y(o)Y,这下看清楚了吧!今天也要加油( ⊙ o ⊙ )

读完文章,也想定制专属网站?

尧图设计师 24 小时内与您沟通定制方案

免费获取报价 →
↑