def test_imshow_keypoints(): # 2D keypoint img = np.zeros((100, 100, 3), dtype=np.uint8) kpts = np.array([[1, 1, 1], [10, 10, 1]], dtype=np.float32) pose_result = [kpts] skeleton = [[0, 1]] pose_kpt_color = [(127, 127, 127)] * len(kpts) pose_link_color = [(127, 127, 127)] * len(skeleton) img_vis_2d = imshow_keypoints( img, pose_result, skeleton=skeleton, pose_kpt_color=pose_kpt_color, pose_link_color=pose_link_color, show_keypoint_weight=True) # 3D keypoint kpts_3d = np.array([[0, 0, 0, 1], [1, 1, 1, 1]], dtype=np.float32) pose_result_3d = [{'keypoints_3d': kpts_3d, 'title': 'test'}] _ = imshow_keypoints_3d( pose_result_3d, img=img_vis_2d, skeleton=skeleton, pose_kpt_color=pose_kpt_color, pose_link_color=pose_link_color, vis_height=400)
def test_imshow_keypoints_3d(): img = np.zeros((100, 100, 3), dtype=np.uint8) kpts_3d = np.array([[0, 0, 0, 1], [1, 1, 1, 1]], dtype=np.float32) pose_result_3d = [{'keypoints_3d': kpts_3d, 'title': 'test'}] skeleton = [[0, 1]] pose_kpt_color = [(127, 127, 127)] * len(kpts_3d) pose_link_color = [(127, 127, 127)] * len(skeleton) _ = imshow_keypoints_3d(pose_result_3d, img=img, skeleton=skeleton, pose_kpt_color=pose_kpt_color, pose_link_color=pose_link_color, vis_height=400) # multiview 3D keypoint pose_result_3d = [kpts_3d] _ = imshow_multiview_keypoints_3d(pose_result_3d, skeleton=skeleton, pose_kpt_color=pose_kpt_color, pose_link_color=pose_link_color, space_size=[8, 8, 8], space_center=[0, 0, 0], kpt_score_thr=0.0)
def show_result(self, result, img=None, skeleton=None, pose_kpt_color=None, pose_link_color=None, radius=8, thickness=2, vis_height=400, num_instances=-1, axis_azimuth=70, win_name='', show=False, wait_time=0, out_file=None): """Visualize 3D pose estimation results. Args: result (list[dict]): The pose estimation results containing: - "keypoints_3d" ([K,4]): 3D keypoints - "keypoints" ([K,3] or [T,K,3]): Optional for visualizing 2D inputs. If a sequence is given, only the last frame will be used for visualization - "bbox" ([4,] or [T,4]): Optional for visualizing 2D inputs - "title" (str): title for the subplot img (str or Tensor): Optional. The image to visualize 2D inputs on. skeleton (list of [idx_i,idx_j]): Skeleton described by a list of links, each is a pair of joint indices. pose_kpt_color (np.array[Nx3]`): Color of N keypoints. If None, do not draw keypoints. pose_link_color (np.array[Mx3]): Color of M links. If None, do not draw links. radius (int): Radius of circles. thickness (int): Thickness of lines. vis_height (int): The image height of the visualization. The width will be N*vis_height depending on the number of visualized items. num_instances (int): Number of instances to be shown in 3D. If smaller than 0, all the instances in the result will be shown. Otherwise, pad or truncate the result to a length of num_instances. axis_azimuth (float): axis azimuth angle for 3D visualizations. win_name (str): The window name. show (bool): Whether to directly show the visualization. wait_time (int): Value of waitKey param. Default: 0. out_file (str or None): The filename to write the image. Default: None. Returns: Tensor: Visualized img, only if not `show` or `out_file`. """ if num_instances < 0: assert len(result) > 0 result = sorted(result, key=lambda x: x.get('track_id', 1e4)) # draw image and input 2d poses if img is not None: img = mmcv.imread(img) bbox_result = [] pose_input_2d = [] for res in result: if 'bbox' in res: bbox = np.array(res['bbox']) if bbox.ndim != 1: assert bbox.ndim == 2 bbox = bbox[-1] # Get bbox from the last frame bbox_result.append(bbox) if 'keypoints' in res: kpts = np.array(res['keypoints']) if kpts.ndim != 2: assert kpts.ndim == 3 kpts = kpts[-1] # Get 2D keypoints from the last frame pose_input_2d.append(kpts) if len(bbox_result) > 0: bboxes = np.vstack(bbox_result) imshow_bboxes( img, bboxes, colors='green', thickness=thickness, show=False) if len(pose_input_2d) > 0: imshow_keypoints( img, pose_input_2d, skeleton, kpt_score_thr=0.3, pose_kpt_color=pose_kpt_color, pose_link_color=pose_link_color, radius=radius, thickness=thickness) img = mmcv.imrescale(img, scale=vis_height / img.shape[0]) img_vis = imshow_keypoints_3d( result, img, skeleton, pose_kpt_color, pose_link_color, vis_height, num_instances=num_instances, axis_azimuth=axis_azimuth, ) if show: mmcv.visualization.imshow(img_vis, win_name, wait_time) if out_file is not None: mmcv.imwrite(img_vis, out_file) return img_vis