Spaces:
Running
on
T4
Running
on
T4
File size: 1,280 Bytes
a73717c |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
import h5py
import numpy as np
import open3d
import os
class IO:
@classmethod
def get(cls, file_path):
_, file_extension = os.path.splitext(file_path)
if file_extension in ['.npy']:
return cls._read_npy(file_path)
elif file_extension in ['.pcd']:
return cls._read_pcd(file_path)
elif file_extension in ['.h5']:
return cls._read_h5(file_path)
elif file_extension in ['.txt']:
return cls._read_txt(file_path)
else:
raise Exception('Unsupported file extension: %s' % file_extension)
# References: https://github.com/numpy/numpy/blob/master/numpy/lib/format.py
@classmethod
def _read_npy(cls, file_path):
return np.load(file_path)
# References: https://github.com/dimatura/pypcd/blob/master/pypcd/pypcd.py#L275
# Support PCD files without compression ONLY!
@classmethod
def _read_pcd(cls, file_path):
pc = open3d.io.read_point_cloud(file_path)
ptcloud = np.array(pc.points)
return ptcloud
@classmethod
def _read_txt(cls, file_path):
return np.loadtxt(file_path)
@classmethod
def _read_h5(cls, file_path):
f = h5py.File(file_path, 'r')
return f['data'][()] |