欢迎光临
我们一直在努力

点云数据转换成pcd

在进行3D模型特征分析的时候,下载了一些3D模型,但是因为文件格式而受到了很多限制。这里提供一种简单的利用python程序将asc文件批量转换为pcd文件。代码如下:

import timefrom sys import argvdef convert(filename): print(‘the input file name is :’,filename) print(‘open the file…..’) file = open(filename,’r+’) count = 0 for line in file: count += 1 file.close() f_prefix = filename.split(‘.’)[0] output_filename = ‘{prefix}.pcd’.format(prefix=f_prefix) output = open(output_filename, “w+”) list = [‘# .PCD v0.7 – Point Cloud Data file format\n’, ‘VERSION 0.7\n’, ‘FIELDS x y z intensity\n’, ‘SIZE 4 4 4 4\n’, ‘TYPE F F F F\n’, ‘COUNT 1 1 1 1\n’, “VIEWPOINT 0 0 0 1 0 0 0\n”] 便宜美国vps output.writelines(list) output.write(‘WIDTH ‘) output.write(str(count)) output.write(‘\nHEIGHT ‘) output.write(str(1)) output.write(‘\nPOINTS ‘) output.write(str(count)) output.write(‘\nDATA ascii\n’) file1 = open(filename, “r”) all = file1.read() output.write(all) output.close() file1.close()import ositems = os.listdir(“.”)newlist = []for names in items: if names.endswith(“.asc”): newlist.append(names)for i in newlist: convert(i)

当然如果使用这种方法的话,安装python的相关编译环境是必不可少的。

在asc文件所在的文件夹中新建一个txt文件,将以上代码粘贴复制进去,并修改后缀名为.py(例如ascTOpcd.py),然后在当前文件夹目录下打开命令提示符窗口,输入? python ascTOpcd.py 即可。

??

这里注意,如果asc文件存放在C盘内,可能会出现权限不够的错误:

这时需要以管理员身份打开cmd。

这里感谢https://blog.csdn.net/syc666946/article/details/79868246这篇文章,以上代码来自此文章,我只是在此基础上更加细化了使用过程。除此之外,我根据这篇文章的方法,双击.bat文件后发现不在python环境内无法运行,所以我就简化了一下,将两个文件合并成一个文件,直接使用cmd进入python环境运行.py文件即可。

再次感谢https://blog.csdn.net/syc666946/article/details/79868246这篇文章博主!!!

73439313

赞(0)
【声明】:本博客不参与任何交易,也非中介,仅记录个人感兴趣的主机测评结果和优惠活动,内容均不作直接、间接、法定、约定的保证。访问本博客请务必遵守有关互联网的相关法律、规定与规则。一旦您访问本博客,即表示您已经知晓并接受了此声明通告。