added some visualization tools for lidar pointclouds

This commit is contained in:
Jan Kowalczyk
2024-04-19 13:38:09 +02:00
parent 0907c89cce
commit 0ee3bc82b5
4 changed files with 395 additions and 0 deletions

67
tools/util.py Normal file
View File

@@ -0,0 +1,67 @@
from pointcloudset import Dataset
from pathlib import Path
from argparse import ArgumentTypeError
from subprocess import run
from datetime import timedelta
from matplotlib.colors import Colormap
from matplotlib import colormaps
def load_dataset_from_bag(bag_file_path: Path, pointcloud_topic: str = "/ouster/points") -> Dataset:
return Dataset.from_file(bag_file_path, topic=pointcloud_topic)
def calculate_average_frame_rate(dataset: Dataset):
timestamps = dataset.timestamps
time_deltas = [timestamps[i + 1] - timestamps[i] for i in range(len(timestamps) - 1)]
average_delta = sum(time_deltas, timedelta()) / len(time_deltas)
average_frame_rate = 1 / average_delta.total_seconds()
return average_frame_rate
def existing_file(path_string: str) -> Path:
path = Path(path_string)
if not path.exists():
raise ArgumentTypeError(f"{path} does not exist!")
if not path.is_file():
raise ArgumentTypeError(f"{path} is not a valid file!")
return path
def existing_folder(path_string: str) -> Path:
path = Path(path_string)
if not path.exists():
raise ArgumentTypeError(f"{path} does not exist!")
if not path.is_folder():
raise ArgumentTypeError(f"{path} is not a valid folder!")
return path
def get_colormap_with_special_missing_color(
colormap_name: str, missing_data_color: str = "black", reverse: bool = False
) -> Colormap:
colormap = colormaps[colormap_name] if not reverse else colormaps[f"{colormap_name}_r"]
colormap.set_bad(missing_data_color)
return colormap
def create_video_from_images(input_images_pattern: str, output_file: Path, frame_rate: int) -> None:
# Construct the ffmpeg command
command = [
"ffmpeg",
"-y",
"-framerate",
str(frame_rate),
"-i",
input_images_pattern,
"-c:v",
"libx264",
"-profile:v",
"high",
"-crf",
"20",
"-pix_fmt",
"yuv420p",
output_file.as_posix(),
]
run(command, check=True)