MCPcopy
hub / github.com/PiLiDAR/PiLiDAR / load_pointcloud

Function load_pointcloud

lib/pointcloud.py:249–299  ·  view source on GitHub ↗
(filepath, columns="XYZI", csv_delimiter=",", as_tensor=False, as_array=False)

Source from the content-addressed store, hash-verified

247# load point cloud from file (3D: pcd, ply, e57 | 2D: csv, npy), return as pcd object or numpy table
248# columns parameter: "XYZ" for 3D, "XZ" for 2D vertical, "I" for intensity or "RGB" for color
249def load_pointcloud(filepath, columns="XYZI", csv_delimiter=",", as_tensor=False, as_array=False):
250 ext = os.path.splitext(filepath)[1][1:]
251
252 if ext == "pcd" or ext == "ply":
253 if as_tensor:
254 pcd = o3d.t.io.read_point_cloud(filepath)
255 else:
256 pcd = o3d.io.read_point_cloud(filepath)
257
258 if as_array:
259 return np.column_stack(np.asarray(pcd.points), np.asarray(pcd.colors) * 255)
260
261 elif ext == "e57":
262 # Create an E57 object with read mode and read data
263 e57 = pye57.E57(filepath, mode='r')
264 data = e57.read_scan_raw()
265 e57.close()
266
267 # Create a numpy array with the point cloud data
268 points = np.column_stack([data["cartesianX"], data["cartesianY"], data["cartesianZ"]])
269 colors = np.column_stack([data["colorRed"], data["colorGreen"], data["colorBlue"]])
270
271 if as_array:
272 return np.column_stack(np.asarray(points), np.asarray(colors))
273
274 # Normalize the color values to the range [0, 1]
275 colors = colors / 255
276
277 # Create an open3d point cloud object
278 pcd = o3d.geometry.PointCloud()
279 pcd.points = o3d.utility.Vector3dVector(points)
280 pcd.colors = o3d.utility.Vector3dVector(colors)
281
282 elif ext == "csv":
283 array = np.loadtxt(filepath, delimiter=csv_delimiter)
284 if as_array:
285 return array
286
287 pcd = pcd_from_np(array, columns=columns)
288
289 elif ext == 'npy':
290 array = np.load(filepath)
291 if as_array:
292 return array
293
294 pcd = pcd_from_np(array, columns=columns)
295
296 else:
297 raise ValueError("Unsupported file type: " + ext)
298
299 return pcd
300
301# export point cloud to file (pcd, ply, e57, csv)
302def save_pointcloud(pcd, filepath, ply_ascii=False, ply_compression=True, csv_delimiter=","):

Callers 5

filter_3D.pyFile · 0.90
get_cartesian_listFunction · 0.85
pointcloud.pyFile · 0.85

Calls 2

pcd_from_npFunction · 0.85
closeMethod · 0.45

Tested by

no test coverage detected