Skip to content

Commit

Permalink
Fix a bug that first frame of depth cam is not properly rendered
Browse files Browse the repository at this point in the history
  • Loading branch information
pengzhenghao committed Dec 15, 2024
1 parent 2b6f5d3 commit ab0f40b
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 0 deletions.
2 changes: 2 additions & 0 deletions metadrive/envs/base_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -566,6 +566,8 @@ def reset_sensors(self):
for name, sensor in self.engine.sensors.items():
if hasattr(sensor, "track") and name != "main_camera":
sensor.track(current_track_agent.origin, [0., 0.8, 1.5], [0, 0.59681, 0])
# Step the env to avoid the black screen in the first frame.
self.engine.taskMgr.step()

def _get_reset_return(self, reset_info):
# TODO: figure out how to get the information of the before step
Expand Down
70 changes: 70 additions & 0 deletions metadrive/tests/test_functionality/test_first_frame_depth_cam.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import tqdm

from metadrive.component.sensors.depth_camera import DepthCamera
from metadrive.engine.asset_loader import AssetLoader
from metadrive.envs.scenario_env import ScenarioEnv
from metadrive.policy.replay_policy import ReplayEgoCarPolicy


def test_first_frame_depth_cam():
env = ScenarioEnv(
{
# To enable onscreen rendering, set this config to True.
"use_render": False,

# !!!!! To enable offscreen rendering, set this config to True !!!!!
"image_observation": True,
"render_pipeline": False,

# ===== The scenario and MetaDrive config =====
"agent_policy": ReplayEgoCarPolicy,
"no_traffic": False,
"sequential_seed": True,
"reactive_traffic": False,
"start_scenario_index": 0,
"num_scenarios": 10,
"horizon": 1000,
"no_static_vehicles": False,
"vehicle_config": dict(
show_navi_mark=False,
use_special_color=False,
image_source="depth_camera",
lidar=dict(num_lasers=120, distance=50),
lane_line_detector=dict(num_lasers=0, distance=50),
side_detector=dict(num_lasers=12, distance=50)
),
"data_directory": AssetLoader.file_path("nuscenes", unix_style=False),

# ===== Set some sensor and visualization configs =====
"daytime": "08:10",
"window_size": (800, 450),
"camera_dist": 0.8,
"camera_height": 1.5,
"camera_pitch": None,
"camera_fov": 60,
"interface_panel": ["semantic_camera"],
"sensors": dict(
# semantic_camera=(SemanticCamera, 1600, 900),
depth_camera=(DepthCamera, 800, 600),
# rgb_camera=(RGBCamera, 800, 600),
),

# ===== Remove useless items in the images =====
"show_logo": False,
"show_fps": False,
"show_interface": True,
}
)

for ep in tqdm.trange(5):
env.reset()
for t in range(10000):
img = env.engine.get_sensor("depth_camera").get_image(env.agent)
assert not (img == 255).all()
if t == 5:
break
env.step([1, 0.88])


if __name__ == '__main__':
test_first_frame_depth_cam()

0 comments on commit ab0f40b

Please sign in to comment.