Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/e57 #21

Merged
merged 3 commits into from
Sep 22, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/lidar_visualizer/datasets/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ def supported_file_extensions():
"ctm",
"off",
"stl",
"e57",
]


Expand Down
44 changes: 39 additions & 5 deletions src/lidar_visualizer/datasets/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,10 @@ def __getitem__(self, idx):
def _get_point_cloud_reader(self):
"""Attempt to guess with try/catch blocks which is the best point cloud reader to use for
the given dataset folder. Supported readers so far are:

File readers are functions which take a filename as an input and return a tuple of points and colors.
- np.fromfile
- pye57
- open3d
- trimesh.load
- PyntCloud
Expand All @@ -102,7 +105,38 @@ def read_kitti_scan(file):
tried_libraries = []
missing_libraries = []

# 2. Try with Open3D
# 2 Try with pye57
if self.file_extension == "e57":
try:
import pye57
def read_e57_scan(file):
e57 = pye57.E57(file)
point_data = None
color_data = None
# One e57 file can contain multiple scans, scanned from different positions
for i in range(e57.scan_count):
i = e57.read_scan(i, colors=True, ignore_missing_fields=True)
scan_data = np.stack([i["cartesianX"], i["cartesianY"], i["cartesianZ"]], axis=1)
point_data = np.concat([point_data, scan_data]) if point_data is not None else scan_data
try:
scan_color_data = np.stack([i["colorRed"], i["colorGreen"], i["colorBlue"]], axis=1)
color_data = np.concat(
[color_data, scan_color_data]) if color_data is not None else scan_color_data
except KeyError:
pass
# e57 file colors are in 0-255 range
color_data = color_data / 255.0 if color_data is not None else None
return point_data, color_data

return read_e57_scan
except ModuleNotFoundError:
missing_libraries.append("pye57")
print("[WARNING] pye57 not installed")
except:
tried_libraries.append("pye57")


# 3. Try with Open3D
try:
self.o3d.t.io.read_point_cloud(first_scan_file)

Expand All @@ -129,7 +163,7 @@ def read_scan_with_intensities(file):
except:
tried_libraries.append("open3d")

# 3. Try with trimesh
# 4. Try with trimesh
try:
import trimesh

Expand All @@ -140,7 +174,7 @@ def read_scan_with_intensities(file):
except:
tried_libraries.append("trimesh")

# 4. Try with PyntCloud
# 5. Try with PyntCloud
try:
from pyntcloud import PyntCloud

Expand All @@ -151,10 +185,10 @@ def read_scan_with_intensities(file):
except:
tried_libraries.append("pyntcloud")

# If reach this point means that none of the librares exist/could read the file
# If reach this point means that none of the libraries exist/could read the file
if not tried_libraries:
print(
"No 3D library is insallted in your system. Install one of the following "
"No 3D library is installed in your system. Install one of the following "
"to read the pointclouds"
)
print("\n".join(missing_libraries))
Expand Down
Loading