MCPcopy Create free account
hub / github.com/RoboVerseOrg/RoboVerse / run_task

Function run_task

scripts/render_native_gallery.py:198–259  ·  view source on GitHub ↗
(task)

Source from the content-addressed store, hash-verified

196
197
198def run_task(task):
199 _block_upstream() # make the cloned libs unimportable BEFORE touching roboverse_pack
200 import cv2
201 import imageio
202
203 from roboverse_pack.tasks.simpler_env._native.overlay import (
204 apply_greenscreen_overlay,
205 foreground_actor_ids,
206 load_overlay_image,
207 )
208
209 env, overlay_path, get_objs, get_robot, get_scene, get_cam, get_cab = _build(task)
210 _assert_no_upstream()
211 env.reset(seed=0)
212 cam, robot, scene = get_cam(env), get_robot(env), get_scene(env)
213 overlay = load_overlay_image(overlay_path)
214 robot_ids = [lk.get_id() for lk in robot.get_links()]
215 cab = get_cab(env) if get_cab else None
216 extra_ids = [lk.get_id() for lk in cab.get_links()] if cab is not None else []
217
218 def frame():
219 scene.update_render()
220 cam.take_picture()
221 color = cam.get_float_texture("Color")[..., :3]
222 raw = np.clip(color * 255, 0, 255).astype(np.uint8)
223 try:
224 seg = cam.get_uint32_texture("Segmentation")[..., 1]
225 fg = foreground_actor_ids(robot_ids, [o.get_id() for o in get_objs(env)], extra_ids)
226 ov = apply_greenscreen_overlay(color.astype(np.float64), seg, overlay, foreground_actor_ids=fg)
227 ovi = np.clip(ov * 255, 0, 255).astype(np.uint8)
228 except Exception:
229 ovi = raw
230 h = raw.shape[0]
231 bar = np.full((h, 4, 3), 255, np.uint8)
232 return np.concatenate([raw, bar, ovi], axis=1)
233
234 frames = [frame()]
235 for a in _scripted_actions():
236 env.step(a)
237 frames.append(frame())
238 # pad to a few extra still frames at the end
239 frames += [frames[-1]] * 3
240
241 os.makedirs(OUT_DIR, exist_ok=True)
242 out = f"{OUT_DIR}/{task}.mp4"
243 # label
244 labeled = []
245 for f in frames:
246 f = f.copy()
247 cv2.putText(f, "native sim", (8, 24), cv2.FONT_HERSHEY_SIMPLEX, 0.7, (0, 0, 0), 2)
248 cv2.putText(
249 f,
250 "visual-matching (native overlay)",
251 (f.shape[1] // 2 + 12, 24),
252 cv2.FONT_HERSHEY_SIMPLEX,
253 0.6,
254 (0, 0, 0),
255 2,

Callers 1

mainFunction · 0.70

Calls 9

load_overlay_imageFunction · 0.90
_block_upstreamFunction · 0.85
_buildFunction · 0.85
_assert_no_upstreamFunction · 0.85
_scripted_actionsFunction · 0.85
printFunction · 0.85
frameFunction · 0.70
resetMethod · 0.45
stepMethod · 0.45

Tested by

no test coverage detected