class_docstr: Visualizer that draws data about detection/segmentation on images.
  
  It contains methods like `draw_{text,box,circle,line,binary_mask,polygon}`
  that draw primitive objects to images, as well as high-level wrappers like
  `draw_{instance_predictions,sem_seg,panoptic_seg_predictions,dataset_dict}`
  that draw composite data in some pre-defined style.
  
  Note that the exact visualization style for the high-level wrappers are subject to change.
  Style such as color, opacity, label contents, visibility of labels, or even the visibility
  of objects themselves (e.g. when the object is too small) may change according
  to different heuristics, as long as the results still look visually reasonable.
  
  To obtain a consistent style, you can implement custom drawing functions with the
  abovementioned primitive methods instead. If you need more customized visualization
  styles, you can process the data yourself following their format documented in
  tutorials (:doc:`/tutorials/models`, :doc:`/tutorials/datasets`). This class does not
  intend to satisfy everyone's preference on drawing styles.
  
  This visualizer focuses on high rendering quality rather than performance. It is not
  designed to be used for real-time applications.
class_docstr_tok: ["Visualizer","that","draws","data","about","detection\/segmentation","on","images",".","It","contains","methods","like","`","draw_","{","text",",","box",",","circle",",","line",",","binary_mask",",","polygon","}","`","that","draw","primitive","objects","to","images",",","as","well","as","high-level","wrappers","like","`","draw_","{","instance_predictions",",","sem_seg",",","panoptic_seg_predictions",",","dataset_dict","}","`","that","draw","composite","data","in","some","pre-defined","style",".","Note","that","the","exact","visualization","style","for","the","high-level","wrappers","are","subject","to","change",".","Style","such","as","color",",","opacity",",","label","contents",",","visibility","of","labels",",","or","even","the","visibility","of","objects","themselves","(","e.g",".","when","the","object","is","too","small",")","may","change","according","to","different","heuristics",",","as","long","as","the","results","still","look","visually","reasonable",".","To","obtain","a","consistent","style",",","you","can","implement","custom","drawing","functions","with","the","abovementioned","primitive","methods","instead",".","If","you","need","more","customized","visualization","styles",",","you","can","process","the","data","yourself","following","their","format","documented","in","tutorials","(",":","doc",":","`","\/tutorials\/models","`",",",":","doc",":","`","\/tutorials\/datasets","`",")",".","This","class","does","not","intend","to","satisfy","everyone","'s","preference","on","drawing","styles",".","This","visualizer","focuses","on","high","rendering","quality","rather","than","performance",".","It","is","not","designed","to","be","used","for","real-time","applications","."]
docstr: 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 keypoints
          and the last dimension corresponds to (x, y, probability).
  
  Returns:
      output (VisImage): image object with visualizations.
docstr_tok: ["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","keypoints","and","the","last","dimension","corresponds","to","(","x",",","y",",","probability",")",".","Returns",":","output","(","VisImage",")",":","image","object","with","visualizations","."]
code: def draw_and_connect_keypoints(self, keypoints):
      """
      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 keypoints
              and the last dimension corresponds to (x, y, probability).
  
      Returns:
          output (VisImage): image object with visualizations.
      """
      visible = {}
      keypoint_names = self.metadata.get("keypoint_names")
      for idx, keypoint in enumerate(keypoints):
          # draw keypoint
          x, y, prob = keypoint
          if prob > self.keypoint_threshold:
              self.draw_circle((x, y), color=_RED)
              if keypoint_names:
                  keypoint_name = keypoint_names[idx]
                  visible[keypoint_name] = (x, y)
  
      if self.metadata.get("keypoint_connection_rules"):
          for (
              kp0,
              kp1,
              color,
          ) in self.metadata.keypoint_connection_rules:
              if kp0 in visible and kp1 in visible:
                  x0, y0 = visible[kp0]
                  x1, y1 = visible[kp1]
                  color = tuple(x / 255.0 for x in color)
                  self.draw_line([x0, x1], [y0, y1], color=color)
  
      # draw lines from nose to mid-shoulder and mid-shoulder to mid-hip
      # Note that this strategy is specific to person keypoints.
      # For other keypoints, it should just do nothing
      try:
          ls_x, ls_y = visible["left_shoulder"]
          rs_x, rs_y = visible["right_shoulder"]
          mid_shoulder_x, mid_shoulder_y = (ls_x + rs_x) / 2, (
              ls_y + rs_y
          ) / 2
      except KeyError:
          pass
      else:
          # draw line from nose to mid-shoulder
          nose_x, nose_y = visible.get("nose", (None, None))
          if nose_x is not None:
              self.draw_line(
                  [nose_x, mid_shoulder_x],
                  [nose_y, mid_shoulder_y],
                  color=_RED,
              )
  
          try:
              # draw line from mid-shoulder to mid-hip
              lh_x, lh_y = visible["left_hip"]
              rh_x, rh_y = visible["right_hip"]
          except KeyError:
              pass
          else:
              mid_hip_x, mid_hip_y = (lh_x + rh_x) / 2, (
                  lh_y + rh_y
              ) / 2
              self.draw_line(
                  [mid_hip_x, mid_shoulder_x],
                  [mid_hip_y, mid_shoulder_y],
                  color=_RED,
              )
      return self.output
  
imports: import colorsys
  import logging
  import math
  import numpy
  from enum import Enum, unique
  import cv2
  import matplotlib
  import matplotlib.colors
  import matplotlib.figure
  import pycocotools.mask
  import torch
  from matplotlib.backends.backend_agg import FigureCanvasAgg
  from PIL import Image
  from detectron2.data import MetadataCatalog
  from detectron2.structures import BitMasks, Boxes, BoxMode, Keypoints, PolygonMasks, RotatedBoxes
  from detectron2.utils.file_io import PathManager
  from .colormap import random_color
label_desc: Use image node_id 8 for calling the Visualizer obj's underlying member method code with example usage: obj.draw_and_connect_keypoints(keypoints) and returns: self