convert_ply_to_pcd.py
Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 import os, sys
00003 
00004 header = "# .PCD v.7 - Point Cloud Data file format\n\
00005 FIELDS x y z\n\
00006 SIZE 4 4 4\n\
00007 TYPE F F F\n\
00008 COUNT 1 1 1\n\
00009 WIDTH XXXX\n\
00010 HEIGHT 1\n\
00011 VIEWPOINT 0 0 0 1 0 0 0\n\
00012 POINTS XXXX\n\
00013 DATA ascii"
00014 
00015 def convertPLYToPCD(mesh_file, pcd_file):
00016     input = open(mesh_file)
00017     out = pcd_file
00018     output = open(out, 'w')
00019     write_points = False
00020     points_counter = 0
00021     nr_points = 0
00022     for s in input.xreadlines():
00023         if s.find("element vertex") != -1:
00024             nr_points = int(s.split(" ")[2].rstrip().lstrip())
00025             new_header = header.replace("XXXX", str(nr_points))
00026             output.write(new_header)
00027             output.write("\n")
00028         if s.find("end_header") != -1:
00029             write_points = True
00030             continue
00031         if write_points and points_counter < nr_points:
00032             points_counter = points_counter + 1
00033             output.write(" ".join(s.split(" ", 3)[:3]))
00034 #            output.write("\n")
00035     input.close()
00036     output.close()
00037 
00038 def usage():
00039      print "\nUsage: python ", sys.argv[0], "<input_mesh.ply> <output_cloud.pcd> \n"
00040 
00041 if __name__ == "__main__":
00042     if sys.argv.__len__() != 3:
00043         usage()
00044         sys.exit(2)
00045     mesh_file = sys.argv[1]
00046     pcd_file = sys.argv[2]
00047     convertPLYToPCD(mesh_file, pcd_file)
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Properties Friends Defines


pcl_cloud_tools
Author(s): Nico Blodow, Zoltan-Csaba Marton, Dejan Pangercic
autogenerated on Thu May 23 2013 17:11:35