Reputation: 37
Problem description:
I need to view pcd (point cloud data) files in this specific format (not ply). I've tested libraries such as pypcd (primary solution) and some alternatives such as pyntcloud (secondary solution), open3d, python-pcl and pcd3ply as described in solution proposals 1. and 2. below. 1. I also added the concerned .pcd file that my developer friend said to run with the proposed code.
I added a sample of concerned .pcd file at the end of this question and also a screenshot from dataset header of .csv file in pictures 2 and 3. I've managed to view .pcd files with an open-source software called CloudCompare, from which I will add screenshot at the end of this document in picture.
The head of the dataset in .csv export looks like the following (1st row including timestamp, second row some unknown integer and 3rd row the following 54 parameters, of which the first 8 parameters deal with x,y,z point cloud coordinates followed with RGB data input etc.): grid_pos_x;grid_pos_y;pos_3d_x;pos_3d_y;pos_3d_z;normal_x;normal_y;normal_z
... , while the rest of the rows (4-->2500+) include the corresponding values like this (demonstrating the first 8 as in column snippet): -17;-30;-1.012568473815918;-0.9698562622070312;3.468137264251709;-0.17042680084705353;0.0034385689068585634;-0.9853643178939819
... .
To admins: Please note I'm new to Stack Overflow. I spent couple hours in formulating this question and I'm hopeless to get this problem solved. Please allow answers. I'm 100% willing to accept any modifications that are proposed to make my post better. There is not much documentation available for this domain.
What has been done:
I've used Jupyter Notebook, Google Colab and PyCharm in order to view the files with pypcd, but every time the following error occurs in building python-lzf: Command prompt error log when using pip install for pypcd library
First the error pointed at missing Microsoft Visual Studio to view C++ in Python (+ additionally also loaded cython library) and after which, I tried to execute code in 3 above mentioned IDEs, but always with the same error. While executing with Python 3, the code "from pypcd import pypcd" shown below is supposed to make it work and I also executed it in Python 2 kernel, because support of Python3 for pypcd seems to be uncertain. This might be a dump question, but can I even execute codes in Python2 anymore, since the maintenance has officially ended? So you know; I'm Windows 10 user.
Experimented also with alternative approaches such as open3d and specifically pyntcloud library, which seems to be much better supported and would be a secondary preference to make this work (source: https://github.com/daavoo/pyntcloud), but I get "ValueError: Points must have x, y and z coordinates Here is the base code to read pcd files in pyntcloud:". Data output is told to be in correct format and especially the described pypcd code below should work with out .pcd input.
What I'm aiming to get answers for:
Solutions I've tired:
from pypcd import pypcd import numpy as np #from glob i import numpy
def read_files():
names = glob("*pcd")
names = sorted(names)
data = []
for item in names:
cloud = pypcd.PointCloud.from_path(item)
data.append(cloud)
print(names)
gridx = []
gridy = []
pos_3d_x = []
pos_3d_y = []
pos_3d_z = []
normal_x = []
normal_y = []
normal_z = []
for item in data:
gridx.append(item.pc_data["grid_pos_x"])
gridy.append(item.pc_data["grid_pos_y"])
pos_3d_x.append(item.pc_data["pos_3d_x"])
pos_3d_y.append(item.pc_data["pos_3d_y"])
pos_3d_z.append(item.pc_data["pos_3d_z"])
normal_x.append(item.pc_data["normal_x"])
normal_y.append(item.pc_data["normal_y"])
normal_z.append(item.pc_data["normal_z"])
point_clouds = []
for i in range(0, len(names)):
point_cloud = np.array([np.array(gridx[i]), np.array(gridy[i]), np.array(pos_3d_x[i]), np.array(pos_3d_y[i]), np.array(pos_3d_z[i]), np.array(normal_x[i]), np.array(normal_y[i]), np.array(normal_z[i])])
point_clouds.append(point_cloud)
return np.array(point_clouds)
point_clouds = read_files() print(point_clouds)
2.1 Secondary solution (among implementations in pyntcloud or open3d) would be to enable viewing and processing of pcd files in .csv format, but visualizing them sounds much more complex process compared to directly opening and viewing .pcd files, for which most straight-forward solutions consider .ply file format and in this use case this file format is not possible to use.
With a following pandas command I managed to retrieve 54 .csv columns located in row 3 to be separated with their corresponding values (see picture below the see the output in jupyter);
import numpy as np
import pandas as pd
import csv
import matplotlib.pyplot as plt
dotcloudcsv = pd.read_csv('dot_cloud_original_extended_00001 (1).csv', sep=';', header=0, skiprows=2)
dotcloudcsv.head(50)
But I didn't know how should I proceed with visualizing the .csv data, so I tried;
2.2 Investigating pyntcloud library, which should be a more up-to-date and better supported library, but after trying out the following code examples I got "ValueError: Points must have x, y and z coordinates" in both cases;
my_point_cloud = PyntCloud.from_file("/content/dfs_dot_cloud_primary.pcd")
my_point_cloud.to_file("out_file.obj", internal=["points", "mesh"], header=0, names=["pos_3d_x","pos_3d_y","pos_3d_z"])
and
from pyntcloud import PyntCloud
my_point_cloud = PyntCloud.from_file("/content/dfs_dot_cloud_primary.pcd")
my_point_cloud.to_file("out_file.obj", header=0, skiprows=2, sep=";")
2.3 Last additional solution that came across could with open3d library, but I could not make sense of the code and gave up because of all the earlier frustration.
Some background information for context:
1.Original .csv dataset header of .pcd export
2.View of .csv file in Jupyter with pandas
3.CloudCompare screenshot of viewing the .pcd file
4.Link to pypcd .py file as primary solution
5.Link to discussed .pcd file to be processed
Upvotes: 4
Views: 6668
Reputation: 31
Hey i know it's been a long time but here a quick answer to read and show pcd file. Open3d can also returne normalised value.
import open3d as o3d
cloud = o3d.io.read_point_cloud('path/to/file.pcd')
print(np.asarray(cloud.points))
print(np.asarray(cloud.colors))
print(np.asarray(cloud.normals))
o3d.visualization.draw_geometries([cloud])
Upvotes: 1