Ply and Pcd are formats for storing point clouds. They are basically a list of 3
ID: 3813807 • Letter: P
Question
Ply and Pcd are formats for storing point clouds. They are basically a list of 3d points (x y z) with a slightly different format. This is an example for a ply Format:
ply format ascii 1.0
comment VCGLIB generated
element vertex 9
property float x
property float y
property float z
property uchar red
property uchar green
property uchar blue
property uchar alpha
element face 0
property list uchar
int vertex_indices
end_header
169.345 0.00190678 -356.222 128 138 80 255
170.668 0.00202459 -355.459 58 36 16 255
170.6 0.00285877 -355.877 59 46 45 255
170.307 0.00326565 -354.98 149 107 81 255
170.581 0.00329066 -355.646 61 38 28 255
170.51 0.00389251 -355.671 70 48 44 255
170.198 0.00511375 -354.959 92 57 55 255
170.558 0.00516258 -355.87 76 63 62 255
170.709 0.00550342 -355.155 100 79 55 255
Your task is:
• Look up online what is the format to PCD files.
• Create a Python code that load the attached Ply file
. • Convert the format to Pcd and save it.
• Try to make is as efficient as you can.
• Try to keep the code as clean as possible so it will be read able.
• To check that your Pcd file yours you can download Cloud compare from: http://www.cloudcompare.org/release/
Explanation / Answer
import os, sys header = "# .PCD v.7 - Point Cloud Data file format FIELDS x y z SIZE 4 4 4 TYPE F F F COUNT 1 1 1 WIDTH XXXX HEIGHT 1 VIEWPOINT 0 0 0 1 0 0 0 POINTS XXXX DATA ascii 1.0" def convertPLYToPCD(ply_file, pcd_file): input = open(ply_file) out = pcd_file output = open(out, 'w') write_points = False points_counter = 0 nr_points = 0 for s in input.xreadlines(): if s.find("element vertex") != -1: nr_points = int(s.split(" ")[2].rstrip().lstrip()) new_header = header.replace("XXXX", str(nr_points)) output.write(new_header) output.write(" ") if s.find("end_header") != -1: write_points = True continue if write_points and points_counterRelated Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.