mzhobro commited on
Commit
8516cb1
·
verified ·
1 Parent(s): ff3a4d2

Upload taco_analysis/render_mesh_overlay.py with huggingface_hub

Browse files
taco_analysis/render_mesh_overlay.py CHANGED
@@ -318,7 +318,9 @@ def draw_hand_skeleton(img, joints_world, K, R, T, color):
318
  # ── Hand data loading ─────────────────────────────────────────────────
319
 
320
  def load_hand_skeletons(root, row, frame_idx, mano_root=None):
321
- """Load hand skeleton joint positions via MANO forward kinematics.
 
 
322
 
323
  Returns dict: {'left': (21, 3), 'right': (21, 3)} or empty if missing.
324
  """
@@ -326,11 +328,23 @@ def load_hand_skeletons(root, row, frame_idx, mano_root=None):
326
  if not hand_dir or pd.isna(hand_dir):
327
  return {}
328
 
 
 
 
 
 
 
 
 
 
 
 
 
 
329
  if mano_root is None:
330
  mano_root = root.parent / "mano_v1_2" / "models"
331
 
332
  result = {}
333
- hand_path = root / hand_dir
334
  frame_key = f"{frame_idx + 1:05d}"
335
 
336
  for side in ["left", "right"]:
@@ -350,7 +364,6 @@ def load_hand_skeletons(root, row, frame_idx, mano_root=None):
350
  hand_pose = np.array(frame_data["hand_pose"], dtype=np.float64).ravel()
351
  hand_trans = np.array(frame_data["hand_trans"], dtype=np.float64).ravel()
352
 
353
- # Load shape parameters (betas) if available
354
  betas = None
355
  shape_file = hand_path / f"{side}_hand_shape.pkl"
356
  if shape_file.exists():
@@ -473,11 +486,11 @@ def build_grid(dataset: TACODataset, seq_idx: int, frame_idx: int,
473
  def main():
474
  parser = argparse.ArgumentParser(description="Render mesh + hand overlays on TACO views")
475
  parser.add_argument("--csv", type=Path,
476
- default=Path(__file__).resolve().parent.parent / "taco_info.csv")
477
  parser.add_argument("--root", type=Path,
478
- default=Path(__file__).resolve().parent.parent)
479
  parser.add_argument("--mano-root", type=Path,
480
- default=Path(__file__).resolve().parent.parent / "mano_v1_2" / "models")
481
  parser.add_argument("--save-dir", type=Path,
482
  default=Path(__file__).resolve().parent / "plots" / "mesh_overlay")
483
  parser.add_argument("--n-sequences", type=int, default=5)
 
318
  # ── Hand data loading ─────────────────────────────────────────────────
319
 
320
  def load_hand_skeletons(root, row, frame_idx, mano_root=None):
321
+ """Load pre-computed 3D hand joint positions from hand_joints.npy.
322
+
323
+ Falls back to MANO forward kinematics if .npy not found.
324
 
325
  Returns dict: {'left': (21, 3), 'right': (21, 3)} or empty if missing.
326
  """
 
328
  if not hand_dir or pd.isna(hand_dir):
329
  return {}
330
 
331
+ hand_path = root / hand_dir
332
+
333
+ # Try pre-computed joints first (Hand_Poses_3D/ then Hand_Poses/)
334
+ npy_path_3d = root / hand_dir.replace("Hand_Poses/", "Hand_Poses_3D/", 1) / "hand_joints.npy"
335
+ npy_path = npy_path_3d if npy_path_3d.exists() else hand_path / "hand_joints.npy"
336
+
337
+ if npy_path.exists():
338
+ joints = np.load(str(npy_path), mmap_mode="r")
339
+ fi = min(frame_idx, len(joints) - 1)
340
+ frame_joints = joints[fi].astype(np.float64) # (2, 21, 3)
341
+ return {"left": frame_joints[0], "right": frame_joints[1]}
342
+
343
+ # Fallback: MANO forward kinematics
344
  if mano_root is None:
345
  mano_root = root.parent / "mano_v1_2" / "models"
346
 
347
  result = {}
 
348
  frame_key = f"{frame_idx + 1:05d}"
349
 
350
  for side in ["left", "right"]:
 
364
  hand_pose = np.array(frame_data["hand_pose"], dtype=np.float64).ravel()
365
  hand_trans = np.array(frame_data["hand_trans"], dtype=np.float64).ravel()
366
 
 
367
  betas = None
368
  shape_file = hand_path / f"{side}_hand_shape.pkl"
369
  if shape_file.exists():
 
486
  def main():
487
  parser = argparse.ArgumentParser(description="Render mesh + hand overlays on TACO views")
488
  parser.add_argument("--csv", type=Path,
489
+ default=Path(__file__).resolve().parent.parent.parent / "taco_info.csv")
490
  parser.add_argument("--root", type=Path,
491
+ default=Path(__file__).resolve().parent.parent.parent)
492
  parser.add_argument("--mano-root", type=Path,
493
+ default=Path(__file__).resolve().parent.parent.parent / "mano_v1_2" / "models")
494
  parser.add_argument("--save-dir", type=Path,
495
  default=Path(__file__).resolve().parent / "plots" / "mesh_overlay")
496
  parser.add_argument("--n-sequences", type=int, default=5)