1000字范文,内容丰富有趣,学习的好帮手!
1000字范文 > 【PCL】.asc文件转换为.pcd文件

【PCL】.asc文件转换为.pcd文件

时间:2019-04-02 12:34:18

相关推荐

【PCL】.asc文件转换为.pcd文件

PCL(Point clouds library)处理的点云文件默认的是pcd格式,3D数据文件格式很多,这里仅仅提供.asc转.pcd的

程序原理也很简单,就是暴力的在每个.asc文件前添加几行.pcd的格式代码。

后面附加的是.bat批处理代码。

使用方法:新建两个.txt文件,分别保存下面的python代码和bat代码到两个文件中,命名为convert.py和runPy.bat后双击runPy.bat即可将当前根目录下的所有asc文件都转换成.pcd格式。

import timefrom sys import argv#script,filename = argv# filename = raw_input("please input filename: ")# print ("the input file name is:%r." %filename)def convert(filename):print ("the input file name is:%r." %filename) start = time.time()print("open the file.....")file = open(filename,"r+")count = 0for line in file:count = count + 1print("size is %d" %count)file.close()#output = open("out.pcd","w+")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"]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()end = time.time()print("run time is:",end-start)import ositems = os.listdir(".")newlist = []for names in items:if names.endswith(".asc"):newlist.append(names)for i in newlist:convert(i)

下面的是runPy.bat

python convert.py

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。