MCPcopy Create free account
hub / github.com/MotrixLab/ViMoGen / render_and_save_overlay

Function render_and_save_overlay

motion_rep/motion_checker.py:242–329  ·  view source on GitHub ↗

Render depth and overlay on RGB video.

(
    verts: torch.Tensor,
    faces: torch.Tensor,
    R: torch.Tensor,
    T: torch.Tensor,
    rgb_video_path: str,
    width: int,
    height: int,
    focal: float,
    batch_size: int = 24,
    fps: int = 60,
    output_path: Optional[str] = None,
    verbose: bool = False,
)

Source from the content-addressed store, hash-verified

240
241
242def render_and_save_overlay(
243 verts: torch.Tensor,
244 faces: torch.Tensor,
245 R: torch.Tensor,
246 T: torch.Tensor,
247 rgb_video_path: str,
248 width: int,
249 height: int,
250 focal: float,
251 batch_size: int = 24,
252 fps: int = 60,
253 output_path: Optional[str] = None,
254 verbose: bool = False,
255) -> str:
256 """Render depth and overlay on RGB video."""
257 # Render depth maps
258 start_time = time.time()
259 depth_maps = rendering_batches(
260 verts, faces, width, height, focal, R, T, batch_size=batch_size, render_multiple=True, reverse_axis=False
261 )
262 render_time = time.time() - start_time
263 if verbose:
264 print(f"Rendering time: {render_time:.2f}s")
265
266 # Visualize depth
267 start_time = time.time()
268 depth_images = visualize_depth_map(depth_maps)
269 vis_time = time.time() - start_time
270 if verbose:
271 print(f"Visualization time: {vis_time:.2f}s")
272
273 # Read RGB video and overlay
274 start_time = time.time()
275 cap = cv2.VideoCapture(rgb_video_path)
276 if not cap.isOpened():
277 raise ValueError(f"Cannot open RGB video: {rgb_video_path}")
278
279 # Create output directory if needed
280 output_dir = os.path.dirname(output_path)
281 if output_dir:
282 os.makedirs(output_dir, exist_ok=True)
283
284 # Use ffmpeg for better codec compatibility (H.264)
285 ffmpeg_command = [
286 "ffmpeg",
287 "-loglevel", "quiet",
288 "-y",
289 "-f", "rawvideo",
290 "-vcodec", "rawvideo",
291 "-pix_fmt", "bgr24",
292 "-s", f"{width}x{height}",
293 "-r", str(fps),
294 "-i", "-",
295 "-an",
296 "-vcodec", "libx264",
297 "-pix_fmt", "yuv420p",
298 output_path,
299 ]

Callers 1

motion_visFunction · 0.85

Calls 2

rendering_batchesFunction · 0.85
visualize_depth_mapFunction · 0.85

Tested by

no test coverage detected