Plot a single frame(array) with keypoints, limbs, bbox, index. Args: kp2d_person (np.ndarray): `np.ndarray` shape of (J * 2). canvas (np.ndarray): cv2 image, (H * W * 3) array. limbs (Union[list, dict, np.ndarray], optional): limbs in form of `dict` or 2-dime
(kp2d_person: np.ndarray,
canvas: np.ndarray,
limbs: Union[list, dict,
np.ndarray] = HUMAN_DATA_LIMBS_INDEX,
palette: Optional[Union[dict, np.ndarray]] = None,
draw_bbox: bool = False,
with_number: bool = False,
font_size: Union[float, int] = 0.5,
disable_limbs: bool = False)
| 28 | |
| 29 | |
| 30 | def _plot_kp2d_frame(kp2d_person: np.ndarray, |
| 31 | canvas: np.ndarray, |
| 32 | limbs: Union[list, dict, |
| 33 | np.ndarray] = HUMAN_DATA_LIMBS_INDEX, |
| 34 | palette: Optional[Union[dict, np.ndarray]] = None, |
| 35 | draw_bbox: bool = False, |
| 36 | with_number: bool = False, |
| 37 | font_size: Union[float, int] = 0.5, |
| 38 | disable_limbs: bool = False) -> np.ndarray: |
| 39 | """Plot a single frame(array) with keypoints, limbs, bbox, index. |
| 40 | |
| 41 | Args: |
| 42 | kp2d_person (np.ndarray): `np.ndarray` shape of (J * 2). |
| 43 | canvas (np.ndarray): cv2 image, (H * W * 3) array. |
| 44 | limbs (Union[list, dict, np.ndarray], optional): limbs in form of |
| 45 | `dict` or 2-dimensional `list` or `np.ndarray` of shape |
| 46 | (num_limb, 2). |
| 47 | `dict` is used mainly for function `visualize_kp2d`, you can also |
| 48 | get the limbs by function `search_limbs`. |
| 49 | Defaults to `HUMAN_DATA_LIMBS_INDEX`. |
| 50 | palette (Optional[Union[dict, np.ndarray, list]], optional): |
| 51 | Pass an (1, 3) `np.ndarray` or `list` [B, G, R] if want the whole |
| 52 | limbs and keypoints will be in same color. |
| 53 | Pass `None` to use our colorful palette. |
| 54 | Pass an (num_limb, 3) `np.ndarray` to get each limb your specific |
| 55 | color. |
| 56 | `dict` is used mainly for function `visualize_kp2d`, you can also |
| 57 | get the palette by function `search_limbs`. |
| 58 | Defaults to `HUMAN_DATA_PALETTE`. |
| 59 | draw_bbox (bool, optional): whether need to draw bounding boxes. |
| 60 | Defaults to False. |
| 61 | with_number (bool, optional): whether need to draw index numbers. |
| 62 | Defaults to False. |
| 63 | font_size (Union[float, int], optional): the font size of the index. |
| 64 | Defaults to 0.5. |
| 65 | disable_limbs (bool, optional): whether need to disable drawing limbs. |
| 66 | Defaults to False. |
| 67 | |
| 68 | Returns: |
| 69 | np.ndarray: opencv image of shape (H * W * 3). |
| 70 | """ |
| 71 | # slice the kp2d array |
| 72 | kp2d_person = kp2d_person.copy() |
| 73 | if kp2d_person.shape[-1] >= 3: |
| 74 | kp2d_person = kp2d_person[..., :-1] |
| 75 | warnings.warn( |
| 76 | 'The input array has more than 2-Dimensional coordinates, will' |
| 77 | 'keep only the first 2-Dimensions of the last axis. The new' |
| 78 | f'array shape: {kp2d_person.shape}') |
| 79 | if kp2d_person.ndim == 3 and kp2d_person.shape[0] == 1: |
| 80 | kp2d_person = kp2d_person[0] |
| 81 | assert kp2d_person.ndim == 2 and kp2d_person.shape[ |
| 82 | -1] == 2, f'Wrong input array shape {kp2d_person.shape}, \ |
| 83 | should be (num_kp, 2)' |
| 84 | |
| 85 | if draw_bbox: |
| 86 | bbox = _get_bbox(kp2d_person, canvas, expand=True) |
| 87 | else: |
no test coverage detected