Guest User

Untitled

a guest
Feb 24th, 2018
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.36 KB | None | 0 0
  1. #!/usr/bin/python
  2. import argparse
  3. import subprocess
  4.  
  5. '''
  6. Make sure pcl is installed!
  7. '''
  8.  
  9. def write_ply_header(out_file, nr_of_points):
  10. out_file.write('''ply
  11. format ascii 1.0
  12. element vertex %d
  13. property float x
  14. property float y
  15. property float z
  16. property uchar red
  17. property uchar green
  18. property uchar blue
  19. end_header
  20. ''' %(nr_of_points))
  21.  
  22.  
  23. def main():
  24. parser = argparse.ArgumentParser(description='Convert xyz with colors to ply file format')
  25. parser.add_argument('xyz_file', type=str,
  26. help='xyz input file')
  27. parser.add_argument('output_file', type=str,
  28. help='output ply input file')
  29. results = parser.parse_args()
  30. xyz_file = results.xyz_file
  31. ply_file = results.output_file
  32. print(xyz_file)
  33. print(ply_file)
  34. nr_of_points = sum(1 for line in open(xyz_file))
  35. with open(xyz_file, 'r') as in_file, open(ply_file, 'w') as out_file:
  36. write_ply_header(out_file, nr_of_points)
  37. for line in in_file:
  38. out_file.write(line)
  39.  
  40. # HACK get ply binary format by converting to pcd and back to ply
  41. pcd_file = ply_file + ".pcd"
  42. print("converting to {} and back to ply to make it in binary format".format(pcd_file))
  43. subprocess.check_output(["pcl_ply2pcd", ply_file, pcd_file])
  44. subprocess.check_output(["pcl_pcd2ply", pcd_file, ply_file])
  45.  
  46.  
  47. if __name__ == "__main__":
  48. main()
Add Comment
Please, Sign In to add comment