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

Adds option for RGB rendering #65

Merged
merged 4 commits into from
Jan 2, 2025
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ The latest model is available to download: [[checkpoint](https://drive.google.co
This code belongs to Robotic Systems Lab, ETH Zurich.
All right reserved

**Authors: [Pascal Roth](https://github.com/pascal-roth), [Julian Nubert](https://juliannubert.com/), [Fan Yang](https://github.com/MichaelFYang), [Mayank Mittal](https://mayankm96.github.io/), [Ziqi Fan](https://github.com/fan-ziqi), and [Marco Hutter](https://rsl.ethz.ch/the-lab/people/person-detail.MTIxOTEx.TGlzdC8yNDQxLC0xNDI1MTk1NzM1.html)<br />
**Authors: [Pascal Roth](https://github.com/pascal-roth), [Julian Nubert](https://juliannubert.com/), [Fan Yang](https://github.com/MichaelFYang), [Mayank Mittal](https://mayankm96.github.io/), and [Marco Hutter](https://rsl.ethz.ch/the-lab/people/person-detail.MTIxOTEx.TGlzdC8yNDQxLC0xNDI1MTk1NzM1.html)<br />
Maintainer: Pascal Roth, [email protected]**

The ViPlanner package has been tested under ROS Noetic on Ubuntu 20.04.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,9 @@ def sample_viewpoints(self, nbr_viewpoints: int, seed: int = 1) -> torch.Tensor:
sample_idx_select = torch.randperm(sample_idx.sum())[
: min(nbr_samples_per_point, nbr_viewpoints - sample_locations_count)
]
sample_locations[
sample_locations_count : sample_locations_count + sample_idx_select.shape[0]
] = self.terrain_analyser.samples[sample_idx][sample_idx_select, :2]
sample_locations[sample_locations_count : sample_locations_count + sample_idx_select.shape[0]] = (
self.terrain_analyser.samples[sample_idx][sample_idx_select, :2]
)
sample_locations_count += sample_idx_select.shape[0]
curr_point_idx += 1
# reset point index if all points are sampled
Expand Down Expand Up @@ -157,6 +157,8 @@ def render_viewpoints(self, samples: torch.Tensor):
# create directories
os.makedirs(os.path.join(filedir, "semantics"), exist_ok=True)
os.makedirs(os.path.join(filedir, "depth"), exist_ok=True)
if "rgb" in self.cfg.cameras.values():
os.makedirs(os.path.join(filedir, "rgb"), exist_ok=True)

# save camera configurations
print(f"[INFO] Saving camera configurations to {filedir}.")
Expand Down Expand Up @@ -206,16 +208,18 @@ def render_viewpoints(self, samples: torch.Tensor):
# save images
for idx in range(samples_idx.shape[0]):
# semantic segmentation
if annotator == "semantic_segmentation":
if annotator == "semantic_segmentation" or annotator == "rgb":
if image_data_np.shape[-1] == 1:
# get info data
info = self.scene.sensors[cam].data.info[idx][annotator]["idToLabels"]

# assign each key a color from the VIPlanner color space
info = {
int(k): self.viplanner_sem_meta.class_color["static"]
if v["class"] in ("BACKGROUND", "UNLABELLED")
else self.viplanner_sem_meta.class_color[v["class"]]
int(k): (
self.viplanner_sem_meta.class_color["static"]
if v["class"] in ("BACKGROUND", "UNLABELLED")
else self.viplanner_sem_meta.class_color[v["class"]]
)
for k, v in info.items()
}

Expand All @@ -232,7 +236,11 @@ def render_viewpoints(self, samples: torch.Tensor):
output = image_data_np[idx]

assert cv2.imwrite(
os.path.join(filedir, "semantics", f"{image_idx[cam_idx]}".zfill(4) + ".png"),
os.path.join(
filedir,
"semantics" if annotator == "semantic_segmentation" else "rgb",
f"{image_idx[cam_idx]}".zfill(4) + ".png"
),
cv2.cvtColor(output.astype(np.uint8), cv2.COLOR_RGB2BGR),
)
# depth
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ class TerrainSceneCfg(InteractiveSceneCfg):
height=480,
data_types=["distance_to_image_plane"],
)

# NOTE: remove "rgb" from the data_types to only render the semantic segmentation
semantic_camera = CameraCfg(
prim_path="{ENV_REGEX_NS}/Robot/base/semantic_camera",
offset=CameraCfg.OffsetCfg(pos=(0.510, 0.0, 0.015), rot=(-0.5, 0.5, -0.5, 0.5)),
Expand All @@ -91,7 +93,7 @@ class TerrainSceneCfg(InteractiveSceneCfg):
),
width=1280,
height=720,
data_types=["semantic_segmentation"],
data_types=["semantic_segmentation", "rgb"],
colorize_semantic_segmentation=False,
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from omni.isaac.lab.managers import ObservationTermCfg as ObsTerm
from omni.isaac.lab.managers import SceneEntityCfg
from omni.isaac.lab.scene import InteractiveSceneCfg
from omni.isaac.lab.sensors import ContactSensorCfg, patterns
from omni.isaac.lab.sensors import ContactSensorCfg, patterns, CameraCfg
from omni.isaac.lab.utils import configclass
from omni.isaac.matterport.config import MatterportImporterCfg
from omni.isaac.matterport.domains import MatterportRayCasterCfg
Expand Down Expand Up @@ -121,6 +121,17 @@ class TerrainSceneCfg(InteractiveSceneCfg):
debug_vis=False,
mesh_prim_paths=["${USER_PATH_TO_USD}/matterport.ply"],
)

# NOTE: comment the following lines to only render the semantic segmentation and depth images
rgb_camera = CameraCfg(
prim_path="{ENV_REGEX_NS}/Robot/base/rgb_camera",
offset=CameraCfg.OffsetCfg(pos=(0.510, 0.0, 0.015), rot=(-0.5, 0.5, -0.5, 0.5)),
spawn=sim_utils.PinholeCameraCfg(),
width=1280,
height=720,
data_types=["rgb"],
colorize_semantic_segmentation=False,
)


@configclass
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,13 +80,15 @@ class TerrainSceneCfg(InteractiveSceneCfg):
height=480,
data_types=["distance_to_image_plane"],
)

# NOTE: remove "rgb" from the data_types to only render the semantic segmentation
semantic_camera = CameraCfg(
prim_path="{ENV_REGEX_NS}/Robot/base/semantic_camera",
offset=CameraCfg.OffsetCfg(pos=(0.510, 0.0, 0.015), rot=(-0.5, 0.5, -0.5, 0.5)),
spawn=sim_utils.PinholeCameraCfg(),
width=1280,
height=720,
data_types=["semantic_segmentation"],
data_types=["semantic_segmentation", "rgb"],
colorize_semantic_segmentation=False,
)

Expand Down
7 changes: 7 additions & 0 deletions omniverse/standalone/data_collect.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,13 @@ def main():
"semantic_camera": "semantic_segmentation",
}

# adustments if also RGB images should be rendered
if args_cli.scene == "matterport" and hasattr(scene_cfg, "rgb_camera"):
scene_cfg.rgb_camera.prim_path = "/World/rgb_camera"
cfg.cameras["rgb_camera"] = "rgb"
elif "rgb" in scene_cfg.semantic_camera.data_types:
cfg.cameras["semantic_camera"] = "rgb"

# Load kit helper
sim_cfg = sim_utils.SimulationCfg()
sim = SimulationContext(sim_cfg)
Expand Down
Loading