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

Fix a bug that first frame of depth cam is not properly rendered #787

Merged
merged 5 commits into from
Dec 16, 2024
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: 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_sensors/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"],
# "show_interface": True,
"sensors": dict(
# semantic_camera=(SemanticCamera, 1600, 900),
depth_camera=(DepthCamera, 800, 600),
# rgb_camera=(RGBCamera, 800, 600),
),
}
)

for ep in tqdm.trange(5):
env.reset()
for t in range(10000):

img = env.engine.get_sensor("depth_camera").perceive(False)
# 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()
Loading