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

NEW LIDAR Visualizer #18

Merged
merged 33 commits into from
Aug 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
34f188e
Visualizer initialized, very fast
l00p3 Aug 9, 2024
6eec6ef
Play mode smaller and previous frame button
l00p3 Aug 12, 2024
099ff92
Amazing slider added
l00p3 Aug 12, 2024
9565c70
Better Progress Bar
l00p3 Aug 12, 2024
8b87c95
Previous frame bug solved
l00p3 Aug 12, 2024
b8d2ef8
gitignore update
l00p3 Aug 12, 2024
73f207b
Name of the window is now correct
l00p3 Aug 12, 2024
6f6e81e
Loading for generic improved and for rosbag done
l00p3 Aug 12, 2024
5a4aedb
'Jumpable' dataloader better handled
l00p3 Aug 12, 2024
8649534
Complete handling for non random accessible dataset done
l00p3 Aug 12, 2024
651bf83
helipr dataloader done
l00p3 Aug 12, 2024
1080ffa
Some open3d import deleted
l00p3 Aug 12, 2024
482c4d9
Ouster loader done
l00p3 Aug 12, 2024
5e86593
Fix jump issue and n_scans available also for
l00p3 Aug 12, 2024
426fecf
Warning updated
l00p3 Aug 12, 2024
4d54806
Another jump issue fixed
l00p3 Aug 12, 2024
41795c4
Jump and n-scans logic fixed
l00p3 Aug 12, 2024
630c8c6
Points size controller added
l00p3 Aug 12, 2024
e5d9ddc
More constants
l00p3 Aug 12, 2024
eeeac7f
Style fix and polyscope in pyproject
l00p3 Aug 12, 2024
0a661f1
Remove weird file and fix points size
l00p3 Aug 13, 2024
2e7087a
Update src/lidar_visualizer/visualizer.py
l00p3 Aug 13, 2024
fd703d2
Center viewpoint and license update
l00p3 Aug 13, 2024
7076b7b
Update src/lidar_visualizer/visualizer.py
l00p3 Aug 13, 2024
5fd4509
Point
l00p3 Aug 13, 2024
577ddb4
Speed level added
l00p3 Aug 13, 2024
e97fb44
Beautify
l00p3 Aug 13, 2024
9a17b12
Fix the Quit button margins
saurabh1002 Aug 13, 2024
d267411
Cosmetics
saurabh1002 Aug 13, 2024
4a05d02
Better point size range
l00p3 Aug 14, 2024
ac0ed86
change point size, again
nachovizzo Aug 15, 2024
7f0bb76
increase point size
nachovizzo Aug 15, 2024
faa511b
Make Cosmetics guy happy
l00p3 Aug 15, 2024
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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
.polyscope.ini
imgui.ini

# Created by https://www.toptal.com/developers/gitignore/api/python
# Edit at https://www.toptal.com/developers/gitignore?templates=python

Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ dependencies = [
"natsort",
"numpy",
"tqdm",
"polyscope>=2.2.1",
"typer[all]>=0.6.0",
]

Expand Down
25 changes: 14 additions & 11 deletions src/lidar_visualizer/datasets/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def _get_point_cloud_reader(self):
- trimesh.load
- PyntCloud
"""
# This is easy, the old KITTI format
# 1. The old KITTI format
if self.file_extension == "bin":
print("[WARNING] Reading .bin files, the only format supported is the KITTI format")

Expand All @@ -92,57 +92,60 @@ def read_kitti_scan(file):
)
points = points_xyzi[:, 0:3]
intensity = points_xyzi[:, -1]
scan = self.o3d.geometry.PointCloud()
intensity = intensity / intensity.max()
colors = self.cmap(intensity)[:, :3].reshape(-1, 3)
scan.points = self.o3d.utility.Vector3dVector(points)
scan.colors = self.o3d.utility.Vector3dVector(colors)
return scan
return points, colors

return read_kitti_scan

first_scan_file = self.scan_files[0]
tried_libraries = []
missing_libraries = []
# First with open3d

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

def read_scan_with_intensities(file):
scan = self.o3d.t.io.read_point_cloud(file)

if "colors" in dir(scan.point):
return scan.to_legacy()
scan = scan.to_legacy()
return np.asarray(scan.points), np.asarray(scan.colors)

if "intensity" in dir(scan.point):
intensity = scan.point.intensity.numpy()
intensity = intensity / intensity.max()
scan.point.colors = self.cmap(intensity)[:, :, :3].reshape(-1, 3)
colors = self.cmap(intensity)[:, :, :3].reshape(-1, 3)
return np.asarray(scan.points), colors

# else
return scan.to_legacy()
scan = scan.to_legacy()
return np.asarray(scan.points), None

return read_scan_with_intensities
except ModuleNotFoundError:
missing_libraries.append("open3d")
except:
tried_libraries.append("open3d")

# 3. Try with trimesh
try:
import trimesh

trimesh.load(first_scan_file)
return lambda file: np.asarray(trimesh.load(file).vertices)
return lambda file: np.asarray(trimesh.load(file).vertices), None
except ModuleNotFoundError:
missing_libraries.append("trimesh")
except:
tried_libraries.append("trimesh")

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

PyntCloud.from_file(first_scan_file)
return lambda file: PyntCloud.from_file(file).points[["x", "y", "z"]].to_numpy()
return lambda file: PyntCloud.from_file(file).points[["x", "y", "z"]].to_numpy(), None
except ModuleNotFoundError:
missing_libraries.append("pyntcloud")
except:
Expand Down
15 changes: 2 additions & 13 deletions src/lidar_visualizer/datasets/helipr.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
import importlib
import os
import struct
import sys
Expand All @@ -34,14 +33,6 @@

class HeLiPRDataset:
def __init__(self, data_dir: Path, *_, **__):
try:
self.o3d = importlib.import_module("open3d")
except ModuleNotFoundError as e:
raise ModuleNotFoundError(
"Open3D is not installed on your system, to fix this either "
'run "pip install open3d" '
"or check https://www.open3d.org/docs/release/getting_started.html"
) from e
# Intensity stuff
import matplotlib.cm as cm

Expand Down Expand Up @@ -112,11 +103,9 @@ def get_data(self, idx: int):
def read_point_cloud(self, idx: int):
data = self.get_data(idx)
points = data[:, :3]
scan = self.o3d.geometry.PointCloud()
scan.points = self.o3d.utility.Vector3dVector(points)
colors = None
if self.intensity_channel is not None:
intensity = data[:, self.intensity_channel]
intensity = (intensity - intensity.min()) / (intensity.max() - intensity.min())
colors = self.cmap(intensity)[:, :3].reshape(-1, 3)
scan.colors = self.o3d.utility.Vector3dVector(colors)
return scan
return points, colors
20 changes: 4 additions & 16 deletions src/lidar_visualizer/datasets/ouster.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,7 @@
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.

import glob
import importlib
import os
from typing import Optional

Expand Down Expand Up @@ -90,14 +88,6 @@ def __init__(
raise ModuleNotFoundError(
f'ouster-sdk is not installed on your system, run "pip install ouster-sdk"'
) from e
try:
self.o3d = importlib.import_module("open3d")
except ModuleNotFoundError as e:
raise ModuleNotFoundError(
"Open3D is not installed on your system, to fix this either "
'run "pip install open3d" '
"or check https://www.open3d.org/docs/release/getting_started.html"
) from e

# since we import ouster-sdk's client module locally, we keep it locally as well
self._client = client
Expand Down Expand Up @@ -139,7 +129,6 @@ def __init__(

def get_color_image(self, scan):
"""This function was taken from the Ouster SDK. All rights reserved to Ouster, Inc

https://github.com/ouster-lidar/ouster_example/blob/master/python/src/ouster/sdk/examples/open3d.py
"""
fields = list(scan.fields)
Expand Down Expand Up @@ -173,11 +162,10 @@ def __getitem__(self, idx):
xyz = self._xyz_lut(scan)[sel_flag]
ref = self.get_color_image(scan)[sel_flag]

# Build Open3D object
cloud = self.o3d.geometry.PointCloud()
cloud.points = self.o3d.utility.Vector3dVector(xyz.reshape((-1, 3)))
cloud.colors = self.o3d.utility.Vector3dVector(ref.reshape((-1, 3)))
return cloud
points = xyz.reshape((-1, 3))
colors = ref.reshape((-1, 3))

return points, colors

def __len__(self):
return self._scans_num
7 changes: 3 additions & 4 deletions src/lidar_visualizer/datasets/point_cloud2.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@

import matplotlib.cm as cm
import numpy as np
import open3d as o3d

try:
from rosbags.typesys.types import sensor_msgs__msg__PointCloud2 as PointCloud2
Expand Down Expand Up @@ -77,12 +76,12 @@ def read_point_cloud(msg: PointCloud2):
points_structured["z"],
]
).astype(np.float64)
scan = o3d.geometry.PointCloud(o3d.utility.Vector3dVector(points))
colors = None
if intensity_field:
intensity = points_structured[intensity_field].astype(np.float64)
intensity = intensity / intensity.max()
scan.colors = o3d.utility.Vector3dVector(cm.viridis(intensity)[:, :3].reshape(-1, 3))
return scan
colors = cm.viridis(intensity)[:, :3].reshape(-1, 3)
return points, colors


def read_points(
Expand Down
7 changes: 1 addition & 6 deletions src/lidar_visualizer/lidar_visualizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,12 +151,6 @@ def lidar_visualizer(
if not dataloader:
dataloader, data = guess_dataloader(data, default_dataloader="generic")

if (jump != 0 or n_scans != -1) and dataloader not in jumpable_dataloaders():
print(f"[WARNING] '{dataloader}' does not support '-jump' or '--n_scans'")
print(f"[WARNING] Visualazing entire dataset")
jump = 0
n_scans = -1

Visualizer(
dataset=dataset_factory(
dataloader=dataloader,
Expand All @@ -165,6 +159,7 @@ def lidar_visualizer(
topic=topic,
meta=meta,
),
random_accessible_dataset=dataloader in jumpable_dataloaders(),
n_scans=n_scans,
jump=jump,
).run()
Expand Down
Loading
Loading