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

Method get_keypoints2d

detrsmpl/data/data_structures/smc_reader.py:669–723  ·  view source on GitHub ↗

Get keypoints2d projected from keypoints3d. Args: device (str): Device name, should be Kinect or iPhone. device_id (int): ID of a device, starts from 0. frame_id (int, list or None, optional): int: frame id

(self, device, device_id, frame_id=None, vertical=True)

Source from the content-addressed store, hash-verified

667 raise KeyError(f'Kinect {device_id} has no floor data.')
668
669 def get_keypoints2d(self, device, device_id, frame_id=None, vertical=True):
670 """Get keypoints2d projected from keypoints3d.
671
672 Args:
673 device (str):
674 Device name, should be Kinect or iPhone.
675 device_id (int):
676 ID of a device, starts from 0.
677 frame_id (int, list or None, optional):
678 int: frame id of one selected frame
679 list: a list of frame id
680 None: all frames will be returned
681 Defaults to None.
682 vertical (bool, optional):
683 Only applicable to iPhone as device
684 iPhone assumes horizontal orientation
685 if True, convert data to vertical orientation
686 Defaults to True.
687
688 Returns:
689 Tuple[np.ndarray, np.ndarray]:
690 keypoints2d (N, J, 3) and its mask (J, )
691 """
692 assert device in {
693 'Kinect', 'iPhone'
694 }, f'Undefined device: {device}, should be "Kinect" or "iPhone"'
695 assert device_id >= 0
696
697 kps2d_dict = self.smc['Keypoints2D'][device][str(device_id)]
698 keypoints2d = kps2d_dict['keypoints2d'][...]
699 keypoints2d_mask = kps2d_dict['keypoints2d_mask'][...]
700
701 if frame_id is None:
702 frame_list = range(self.get_keypoints_num_frames())
703 elif isinstance(frame_id, list):
704 frame_list = frame_id
705 elif isinstance(frame_id, int):
706 assert frame_id < self.get_keypoints_num_frames(),\
707 'Index out of range...'
708 frame_list = [frame_id]
709 else:
710 raise TypeError('frame_id should be int, list or None.')
711
712 keypoints2d = keypoints2d[frame_list, ...]
713
714 if device == 'iPhone' and vertical:
715 # rotate keypoints 2D clockwise by 90 degrees
716 W, H = self.get_iphone_color_resolution(vertical=False)
717 xs, ys, conf = \
718 keypoints2d[..., 0], keypoints2d[..., 1], keypoints2d[..., 2]
719 xs, ys = H - ys, xs # horizontal -> vertical
720 keypoints2d[..., 0], keypoints2d[..., 1] = xs.copy(), ys.copy()
721 keypoints2d[conf == 0.0] = 0.0
722
723 return keypoints2d, keypoints2d_mask
724
725 def get_kinect_keypoints2d(self, device_id, frame_id=None):
726 """Get Kinect 2D keypoints.

Callers 2

Calls 3

copyMethod · 0.80

Tested by

no test coverage detected