MCPcopy Create free account
hub / github.com/MotrixLab/AiOS / estimate_cam_weakperspective

Function estimate_cam_weakperspective

detrsmpl/utils/geometry.py:448–494  ·  view source on GitHub ↗

img_size: wh

(joints3d,
        joints2d,
        joints2d_conf,
        joints3d_conf,
        img_size)

Source from the content-addressed store, hash-verified

446
447
448def estimate_cam_weakperspective(joints3d,
449 joints2d,
450 joints2d_conf,
451 joints3d_conf,
452 img_size) -> torch.Tensor:
453 '''
454 img_size: wh
455 '''
456 w, h = img_size
457 if joints2d_conf is not None:
458 valid_ids = torch.where(joints2d_conf.view(-1) > 0)[0]
459 joints2d = joints2d[valid_ids]
460 if joints3d_conf is not None:
461 valid_ids = torch.where(joints3d_conf.view(-1) > 0)[0]
462 joints3d = joints3d[valid_ids]
463 x1 = torch.min(joints3d[..., 0])
464 x2 = torch.max(joints3d[..., 0])
465
466 y1 = torch.min(joints3d[..., 1])
467 y2 = torch.max(joints3d[..., 1])
468
469 # img_size = img_size if isinstance(img_size, int) else int(img_size[0])
470
471 u1 = 2*torch.min(joints2d[..., 0]) / w -1
472 u2 = 2*torch.max(joints2d[..., 0]) / w -1
473 v1 = (2 * torch.min(joints2d[..., 1])-h)/max(w,h)
474 v2 = (2 * torch.max(joints2d[..., 1])-h)/max(w,h)
475
476 # u1 = torch.min(joints2d[..., 0]) / w
477 # u2 = torch.max(joints2d[..., 0]) / w
478 # v1 = torch.min(joints2d[..., 1]) / h
479 # v2 = torch.max(joints2d[..., 1]) / h
480
481 sx = (u1 - u2) / (x1 - x2)
482 sy = (v1 - v2) / (y1 - y2)
483 s = torch.sqrt(sx * sy)
484
485 tx_1 = u1 / s - x1 # u1 = s*(tx_1 + x1)
486 ty_1 = v1 / s - y1 # v1 = s*(ty_1 + y1)
487
488 tx_2 = u2 / s - x2 # u2 = s*(tx_2 + x2)
489 ty_2 = v2 / s - y2 # v2 = s*(ty_2 + y2)
490
491 tx = (tx_1 + tx_2) / 2
492 ty = (ty_1 + ty_2) / 2
493 cam = torch.Tensor([s, tx, ty]).view(3)
494 return cam
495
496def estimate_cam_weakperspective_batch(
497 joints3d, joints2d,

Callers 1

Calls 1

maxMethod · 0.80

Tested by

no test coverage detected