asc文件转换为pcd文件asc2pcd

之前网上搜到的asc2pcd的py脚本不能用,原因是pcd文件前几行size,type不同,我贴一个自己修改过,亲测PCL库可以用的asc转换pcd的脚本

import time
 
from 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 = 0
 
    for line in file:
        count = count + 1
    print("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\n','SIZE 4 4 4\n',
            'TYPE F F F\n','COUNT 1 1 1\n']
    
    output.writelines(list)
    output.write('WIDTH ')
    output.write(str(count))
    output.write('\nHEIGHT ')
    output.write(str(1))
    output.write("\nVIEWPOINT 0 0 0 1 0 0 0")
    output.write('\nPOINTS ')
    output.write(str(count))
    output.write('\nDATA ascii\n')
    #line=line.strip('\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 os
items = 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
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

菜是菜人是真帅

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值