PCD file Format Conversion script

Source: Internet
Author: User

When writing a reconstruction algorithm, it is necessary to use the point coordinate and the normal data file, and then use the normal calculation module in the PCL to generate the normal direction. The post-output method contains curvature information in the file, but this is not required. Then wrote a Python small script to implement the format conversion.

#--coding:utf-8--Import TimeImportNumPy as NP fromSysImportArgvscript, Input_file=Argvinput_data= Open (Input_file,"R") Output_data= Open ("OUTDATA.ASC","W") Doc=" "This script is used for data conversion, converting a PCL-generated file into a point cloud data + normal information + curvature PCD file output as point cloud Data + normal information ASC file after conversion curvature information is filtered, and the format is converted to the general ASC file format" "Print(DOC)#Conversion Functionsdeftransform (Input_data, Output_data): Pointlist= []     forLineinchInput_data:data= Line.split (" ")        ifIs_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#determines whether a string is a numberdefIs_number (s):Try: Float (s)returnTrueexceptValueError:Pass    returnFalsetransform (Input_data, Output_data)

The contents of the original file are:

# . PCD v0.7-point Cloud Data file formatVERSION 0.7Fields x y z normal_x normal_y normal_z curvaturesize4 4 4 4 4 4 4TYPE F F F f f f fcount1 1 1 1 1 1 1WIDTH26381HEIGHT1VIEWPOINT 0 0 010 0 0POINTS26381DATA 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

The converted file contents are:

52.713619 44.306831 2.500001-0.671112-0.085537 0.73640552.542110 45.728249 2.500001-0.672440-0.090179 0.7346 3852.305740 47.160099 2.500001-0.674852-0.106090 0.73028852.022919 48.575920 2.500001-0.673861-0.116867 0.72 955751.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.1652 24 0.87412248.665119 61.585480 2.500001-0.278926-0.127679 0.95178748.067780 62.904530 2.500001-0.263447-0.14 2550 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.5524 79 62.677849 2.500001-0.300091 0.156567-0.94097442.826420 61.414768 2.500001-0.369369 0.196475-0.90827542.20 7859 60.036179 2.500001-0.555614 0.201118-0.80674941.684139 58.620060 2.500001-0.607999 0.191823-0.770416

PCD file Format Conversion script

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.