Draws keypoints of an instance and follows the rules for keypoint connections to draw lines between appropriate keypoints. This follows color heuristics for line color. Args: keypoints (Tensor): a tensor of shape (K, 3), where K is the number of keypoint
(self, keypoints)
| 797 | return self.output |
| 798 | |
| 799 | def draw_and_connect_keypoints(self, keypoints): |
| 800 | """ |
| 801 | Draws keypoints of an instance and follows the rules for keypoint connections |
| 802 | to draw lines between appropriate keypoints. This follows color heuristics for |
| 803 | line color. |
| 804 | |
| 805 | Args: |
| 806 | keypoints (Tensor): a tensor of shape (K, 3), where K is the number of keypoints |
| 807 | and the last dimension corresponds to (x, y, probability). |
| 808 | |
| 809 | Returns: |
| 810 | output (VisImage): image object with visualizations. |
| 811 | """ |
| 812 | visible = {} |
| 813 | keypoint_names = self.metadata.get("keypoint_names") |
| 814 | for idx, keypoint in enumerate(keypoints): |
| 815 | |
| 816 | # draw keypoint |
| 817 | x, y, prob = keypoint |
| 818 | if prob > self.keypoint_threshold: |
| 819 | self.draw_circle((x, y), color=_RED) |
| 820 | if keypoint_names: |
| 821 | keypoint_name = keypoint_names[idx] |
| 822 | visible[keypoint_name] = (x, y) |
| 823 | |
| 824 | if self.metadata.get("keypoint_connection_rules"): |
| 825 | for kp0, kp1, color in self.metadata.keypoint_connection_rules: |
| 826 | if kp0 in visible and kp1 in visible: |
| 827 | x0, y0 = visible[kp0] |
| 828 | x1, y1 = visible[kp1] |
| 829 | color = tuple(x / 255.0 for x in color) |
| 830 | self.draw_line([x0, x1], [y0, y1], color=color) |
| 831 | |
| 832 | # draw lines from nose to mid-shoulder and mid-shoulder to mid-hip |
| 833 | # Note that this strategy is specific to person keypoints. |
| 834 | # For other keypoints, it should just do nothing |
| 835 | try: |
| 836 | ls_x, ls_y = visible["left_shoulder"] |
| 837 | rs_x, rs_y = visible["right_shoulder"] |
| 838 | mid_shoulder_x, mid_shoulder_y = (ls_x + rs_x) / 2, (ls_y + rs_y) / 2 |
| 839 | except KeyError: |
| 840 | pass |
| 841 | else: |
| 842 | # draw line from nose to mid-shoulder |
| 843 | nose_x, nose_y = visible.get("nose", (None, None)) |
| 844 | if nose_x is not None: |
| 845 | self.draw_line([nose_x, mid_shoulder_x], [nose_y, mid_shoulder_y], color=_RED) |
| 846 | |
| 847 | try: |
| 848 | # draw line from mid-shoulder to mid-hip |
| 849 | lh_x, lh_y = visible["left_hip"] |
| 850 | rh_x, rh_y = visible["right_hip"] |
| 851 | except KeyError: |
| 852 | pass |
| 853 | else: |
| 854 | mid_hip_x, mid_hip_y = (lh_x + rh_x) / 2, (lh_y + rh_y) / 2 |
| 855 | self.draw_line([mid_hip_x, mid_shoulder_x], [mid_hip_y, mid_shoulder_y], color=_RED) |
| 856 | return self.output |
no test coverage detected