23 lines
1.3 KiB
Python
23 lines
1.3 KiB
Python
"""渲染 front / side / chest 三个视角到 out/,用于快速目检场景。"""
|
|
import os, sys
|
|
os.environ.setdefault("MUJOCO_GL", "glfw")
|
|
from pathlib import Path
|
|
import mujoco, numpy as np, cv2
|
|
|
|
ROOT = Path(__file__).resolve().parents[1]
|
|
xml = sys.argv[1] if len(sys.argv) > 1 else str(ROOT / "scene/a7l20_scene.xml")
|
|
m = mujoco.MjModel.from_xml_path(xml); d = mujoco.MjData(m)
|
|
import json, sys as _s; _s.path.insert(0, str(ROOT / "scene")); from build_scene import set_home; set_home(m, d, json.load(open(ROOT / "scene/a7l20_scene.json")))
|
|
for _ in range(500): mujoco.mj_step(m, d)
|
|
(ROOT / "out").mkdir(exist_ok=True)
|
|
r = mujoco.Renderer(m, 480, 848)
|
|
for cam in ("front", "side", "chest_cam"):
|
|
r.update_scene(d, camera=cam); img = r.render()
|
|
cv2.imwrite(str(ROOT / f"out/{cam}.png"), cv2.cvtColor(img, cv2.COLOR_RGB2BGR))
|
|
r.enable_depth_rendering(); r.update_scene(d, camera="chest_cam"); dep = r.render(); r.disable_depth_rendering()
|
|
v = dep[np.isfinite(dep) & (dep < 3)]
|
|
print(f"chest depth: min {v.min():.3f} m, median {np.median(v):.3f} m, max {v.max():.3f} m")
|
|
vis = np.clip((dep - v.min()) / (v.max() - v.min() + 1e-6), 0, 1); vis = (255 * (1 - vis)).astype(np.uint8)
|
|
cv2.imwrite(str(ROOT / "out/chest_depth.png"), vis)
|
|
print("saved out/front.png out/side.png out/chest_cam.png out/chest_depth.png")
|