首页 > 代码库 > PCD文件格式转换脚本

PCD文件格式转换脚本

在写一个重建算法的时候需要用到点坐标和法向的数据文件,于是向利用pcl中的法向计算模块来生成法向。输出后法向文件中包含曲率信息,但是这是不需要的。于是自己写了一个python小脚本实现格式转换。

#--coding:utf-8--import timeimport numpy as npfrom  sys import argvscript, input_file = argvinput_data = open(input_file,"r")output_data = open("outdata.asc","w")doc = ‘‘‘本脚本用于数据转换,将PCL生成的文件进行转换  输入为 点云数据+法向信息+曲率  PCD文件  输出为 点云数据+法向信息     ASC文件转换后曲率信息被滤除,并将格式转换为通用的asc文件格式‘‘‘print(doc)#转换函数def transform(input_data, output_data):    pointList = []    for line in input_data:                data = line.split(" ")        if is_number(data[0]):            output_data.write("%f  %f  %f  %f  %f  %f\n"            %((float)(data[0]),              (float)(data[1]),              (float)(data[2]),              (float)(data[3]),              (float)(data[4]),              (float)(data[5])))        else:            pass#判断字符串是否为数字def is_number(s):    try:        float(s)        return True    except ValueError:        pass    return Falsetransform(input_data, output_data)

 

原文件内容为:

# .PCD v0.7 - Point Cloud Data file formatVERSION 0.7FIELDS x y z normal_x normal_y normal_z curvatureSIZE 4 4 4 4 4 4 4TYPE F F F F F F FCOUNT 1 1 1 1 1 1 1WIDTH 26381HEIGHT 1VIEWPOINT 0 0 0 1 0 0 0POINTS 26381DATA ascii52.713619 44.306831 2.500001 -0.67111164 -0.08553692 0.73640519 0.0006154828652.54211 45.728249 2.500001 -0.67243981 -0.090179443 0.73463756 0.0006925871152.30574 47.160099 2.500001 -0.67485178 -0.10609017 0.73028761 0.0004399213152.022919 48.57592 2.500001 -0.67386091 -0.11686694 0.72955716 0.0003756942551.720371 49.97781 2.500001 -0.66632128 -0.11713342 0.73640722 0.0006243303151.405071 51.394611 2.500001 -0.65537727 -0.11913724 0.74584651 0.0009070307751.068241 52.847191 2.500001 -0.6404919 -0.1198745 0.75855136 0.00108206750.717159 54.314861 2.500001 -0.62284762 -0.120147 0.77306247 0.001249774550.349918 55.789589 2.500001 -0.60351694 -0.12188542 0.7879793 0.001389806249.98164 57.264919 2.500001 -0.56129658 -0.1375796 0.81609923 0.001478937949.60405 58.715778 2.500001 -0.53091556 -0.14410463 0.83508235 0.002145263849.167542 60.149521 2.500001 -0.45673963 -0.16522408 0.87412238 0.006495753348.665119 61.58548 2.500001 -0.27892584 -0.12767911 0.95178694 0.015811486

转换后的文件内容为:

52.713619  44.306831  2.500001  -0.671112  -0.085537  0.73640552.542110  45.728249  2.500001  -0.672440  -0.090179  0.73463852.305740  47.160099  2.500001  -0.674852  -0.106090  0.73028852.022919  48.575920  2.500001  -0.673861  -0.116867  0.72955751.720371  49.977810  2.500001  -0.666321  -0.117133  0.73640751.405071  51.394611  2.500001  -0.655377  -0.119137  0.74584751.068241  52.847191  2.500001  -0.640492  -0.119874  0.75855150.717159  54.314861  2.500001  -0.622848  -0.120147  0.77306250.349918  55.789589  2.500001  -0.603517  -0.121885  0.78797949.981640  57.264919  2.500001  -0.561297  -0.137580  0.81609949.604050  58.715778  2.500001  -0.530916  -0.144105  0.83508249.167542  60.149521  2.500001  -0.456740  -0.165224  0.87412248.665119  61.585480  2.500001  -0.278926  -0.127679  0.95178748.067780  62.904530  2.500001  -0.263447  -0.142550  0.95408347.309990  63.906979  2.500001  -0.082274  -0.155248  0.98444346.385601  64.398064  2.500001  -0.025878  -0.196875  0.98008745.383808  64.317551  2.500001  0.015420  -0.199873  0.97970144.408440  63.701160  2.500001  -0.232693  0.125587  -0.96440843.552479  62.677849  2.500001  -0.300091  0.156567  -0.94097442.826420  61.414768  2.500001  -0.369369  0.196475  -0.90827542.207859  60.036179  2.500001  -0.555614  0.201118  -0.80674941.684139  58.620060  2.500001  -0.607999  0.191823  -0.770416

 

PCD文件格式转换脚本