full upload so not to lose anything important

This commit is contained in:
Jan Kowalczyk
2025-03-14 18:02:23 +01:00
parent 35fcfb7d5a
commit b824ff7482
33 changed files with 3539 additions and 353 deletions

View File

@@ -1,21 +1,24 @@
from configargparse import ArgParser, YAMLConfigFileParser, ArgumentDefaultsRawHelpFormatter
from pathlib import Path
from sys import exit
from open3d.visualization.rendering import OffscreenRenderer, MaterialRecord
import matplotlib.pyplot as plt
import numpy as np
from configargparse import (
ArgParser,
ArgumentDefaultsRawHelpFormatter,
YAMLConfigFileParser,
)
from open3d.io import read_pinhole_camera_parameters, write_image
from open3d.utility import Vector3dVector
from pathlib import Path
from open3d.visualization.rendering import MaterialRecord, OffscreenRenderer
from pointcloudset import Dataset
from rich.progress import track
import matplotlib.pyplot as plt
import numpy as np
from util import (
load_dataset,
existing_file,
create_video_from_images,
calculate_average_frame_rate,
create_video_from_images,
existing_file,
load_dataset,
)
@@ -42,14 +45,18 @@ def render_3d_images(
distances = np.linalg.norm(points, axis=1)
max_distance = distances.max()
min_distance = distances.min()
normalized_distances = (distances - min_distance) / (max_distance - min_distance)
normalized_distances = (distances - min_distance) / (
max_distance - min_distance
)
colors = plt.get_cmap("jet")(normalized_distances)[:, :3]
pcd.colors = Vector3dVector(colors)
return pcd
rendered_images = []
for i, pc in track(enumerate(dataset, 1), description="Rendering images...", total=len(dataset)):
for i, pc in track(
enumerate(dataset, 1), description="Rendering images...", total=len(dataset)
):
o3d_pc = pc.to_instance("open3d")
o3d_pc = color_points_by_range(o3d_pc)
renderer.scene.add_geometry("point_cloud", o3d_pc, MaterialRecord())
@@ -68,19 +75,35 @@ def main() -> int:
formatter_class=ArgumentDefaultsRawHelpFormatter,
description="Render a 3d representation of a point cloud",
)
parser.add_argument("--render-config-file", is_config_file=True, help="yaml config file path")
parser.add_argument("--input-bag-path", required=True, type=existing_file, help="path to bag file")
parser.add_argument(
"--tmp-files-path", default=Path("./tmp"), type=Path, help="path temporary files will be written to"
"--render-config-file", is_config_file=True, help="yaml config file path"
)
parser.add_argument(
"--output-images", type=bool, default=True, help="if rendered frames should be outputted as images"
"--input-bag-path", required=True, type=existing_file, help="path to bag file"
)
parser.add_argument(
"--output-images-path", default=Path("./output"), type=Path, help="path rendered frames should be written to"
"--tmp-files-path",
default=Path("./tmp"),
type=Path,
help="path temporary files will be written to",
)
parser.add_argument(
"--output-video", type=bool, default=True, help="if rendered frames should be outputted as a video"
"--output-images",
type=bool,
default=True,
help="if rendered frames should be outputted as images",
)
parser.add_argument(
"--output-images-path",
default=Path("./output"),
type=Path,
help="path rendered frames should be written to",
)
parser.add_argument(
"--output-video",
type=bool,
default=True,
help="if rendered frames should be outputted as a video",
)
parser.add_argument(
"--output-video-path",
@@ -88,7 +111,12 @@ def main() -> int:
type=Path,
help="path rendered video should be written to",
)
parser.add_argument("--output-images-prefix", default="2d_render", type=str, help="filename prefix for output")
parser.add_argument(
"--output-images-prefix",
default="2d_render",
type=str,
help="filename prefix for output",
)
parser.add_argument(
"--camera-config-input-json-path",
default="./saved_camera_settings.json",
@@ -110,12 +138,21 @@ def main() -> int:
dataset = load_dataset(args.input_bag_path)
images = render_3d_images(
dataset, args.camera_config_input_json_path, args.tmp_files_path, args.output_images_prefix
dataset,
args.camera_config_input_json_path,
args.tmp_files_path,
args.output_images_prefix,
)
if args.output_video:
input_images_pattern = f"{args.tmp_files_path / args.output_images_prefix}_%04d.png"
create_video_from_images(input_images_pattern, args.output_video_path, calculate_average_frame_rate(dataset))
input_images_pattern = (
f"{args.tmp_files_path / args.output_images_prefix}_%04d.png"
)
create_video_from_images(
input_images_pattern,
args.output_video_path,
calculate_average_frame_rate(dataset),
)
if not args.output_images:
for image in images: