mirror of
https://github.com/SikongJueluo/Mini-Nav.git
synced 2026-07-12 20:15:31 +08:00
feat(simulator): add image saving utilities for verification
This commit is contained in:
@@ -3,16 +3,19 @@ from .habitat import (
|
||||
close_habitat_simulator,
|
||||
create_habitat_simulator,
|
||||
)
|
||||
from .image_save import save_object_image, save_room_view
|
||||
from .topdown import TopDownRenderStyle, TopDownSceneElements, render_topdown_scene_map
|
||||
from .views import RoomViewsByRoom, collect_room_views_by_room
|
||||
|
||||
__all__ = [
|
||||
"HabitatSimulatorConfig",
|
||||
"RoomViewsByRoom",
|
||||
"TopDownRenderStyle",
|
||||
"TopDownSceneElements",
|
||||
"RoomViewsByRoom",
|
||||
"close_habitat_simulator",
|
||||
"collect_room_views_by_room",
|
||||
"create_habitat_simulator",
|
||||
"render_topdown_scene_map",
|
||||
"save_object_image",
|
||||
"save_room_view",
|
||||
]
|
||||
|
||||
59
mini-nav/simulator/image_save.py
Normal file
59
mini-nav/simulator/image_save.py
Normal file
@@ -0,0 +1,59 @@
|
||||
"""Image saving utilities for simulation verification output."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from pathlib import Path
|
||||
|
||||
from PIL import Image
|
||||
|
||||
|
||||
def save_room_view(
|
||||
output_dir: Path,
|
||||
room_id: str,
|
||||
view_idx: int,
|
||||
image: Image.Image,
|
||||
) -> Path:
|
||||
"""Save a single room view image to disk.
|
||||
|
||||
Args:
|
||||
output_dir: Base output directory.
|
||||
room_id: Room identifier string.
|
||||
view_idx: Zero-based view index within the room.
|
||||
image: PIL Image to save.
|
||||
|
||||
Returns:
|
||||
Path where the image was saved.
|
||||
"""
|
||||
room_dir = output_dir / room_id
|
||||
room_dir.mkdir(parents=True, exist_ok=True)
|
||||
path = room_dir / f"view_{view_idx:03d}.png"
|
||||
image.convert("RGB").save(path, format="PNG")
|
||||
return path
|
||||
|
||||
|
||||
def save_object_image(
|
||||
output_dir: Path,
|
||||
room_id: str,
|
||||
obj_id: str,
|
||||
view_idx: int,
|
||||
mask_idx: int,
|
||||
image: Image.Image,
|
||||
) -> Path:
|
||||
"""Save a masked object image to disk.
|
||||
|
||||
Args:
|
||||
output_dir: Base output directory.
|
||||
room_id: Room identifier string.
|
||||
obj_id: Object identifier string.
|
||||
view_idx: Zero-based view index.
|
||||
mask_idx: Zero-based mask index within the view.
|
||||
image: PIL Image to save.
|
||||
|
||||
Returns:
|
||||
Path where the image was saved.
|
||||
"""
|
||||
room_dir = output_dir / room_id
|
||||
room_dir.mkdir(parents=True, exist_ok=True)
|
||||
path = room_dir / f"{obj_id}_view{view_idx:03d}_mask{mask_idx:02d}.png"
|
||||
image.convert("RGB").save(path, format="PNG")
|
||||
return path
|
||||
Reference in New Issue
Block a user