class_docstr: Visualizer that draws data about detection on images.
  
  It contains methods like `draw_{text,box}`
  that draw primitive objects to images, as well as high-level wrappers like
  `draw_{instance_predictions}` 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.  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","on","images",".","It","contains","methods","like","`","draw_","{","text",",","box","}","`","that","draw","primitive","objects","to","images",",","as","well","as","high-level","wrappers","like","`","draw_","{","instance_predictions","}","`","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",".","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: Draw the visualizations
  Parameters
  ----------
  boxes (Boxes, RotatedBoxes or ndarray): either a :class:`Boxes`,
      or an Nx4 numpy array of XYXY_ABS format for the N objects in a single image,
      or a :class:`RotatedBoxes`,
      or an Nx5 numpy array of (x_center, y_center, width, height, angle_degrees) format
      for the N objects in a single image,
  labels (list[str]): the text to be displayed for each instance.
  assigned_colors (list[matplotlib.colors]): a list of colors, where each color
      corresponds to each mask or box in the image. Refer to 'matplotlib.colors'
      for full list of formats that the colors are accepted in.
  Returns
  -------
      output (VisImage): image object with visualizations.
code: def overlay_instances(
      self,
      *,
      boxes=None,
      labels=None,
      assigned_colors=None,
  ):
      """
      Draw the visualizations
      Parameters
      ----------
      boxes (Boxes, RotatedBoxes or ndarray): either a :class:`Boxes`,
          or an Nx4 numpy array of XYXY_ABS format for the N objects in a single image,
          or a :class:`RotatedBoxes`,
          or an Nx5 numpy array of (x_center, y_center, width, height, angle_degrees) format
          for the N objects in a single image,
      labels (list[str]): the text to be displayed for each instance.
      assigned_colors (list[matplotlib.colors]): a list of colors, where each color
          corresponds to each mask or box in the image. Refer to 'matplotlib.colors'
          for full list of formats that the colors are accepted in.
      Returns
      -------
          output (VisImage): image object with visualizations.
      """
      num_instances = 0
      if boxes is not None:
          num_instances = len(boxes)
      if labels is not None:
          assert len(labels) == num_instances
      if assigned_colors is None:
          assigned_colors = [
              random_color(rgb=True, maximum=1)
              for _ in range(num_instances)
          ]
      if num_instances == 0:
          return self.output
  
      # Display in largest to smallest order to reduce occlusion.
      areas = None
      if boxes is not None:
          areas = np.prod(boxes[:, 2:] - boxes[:, :2], axis=1)
  
      if areas is not None:
          sorted_idxs = np.argsort(-areas).tolist()
          # Re-order overlapped instances in descending order.
          boxes = boxes[sorted_idxs] if boxes is not None else None
          labels = (
              [labels[k] for k in sorted_idxs]
              if labels is not None
              else None
          )
          assigned_colors = [
              assigned_colors[idx] for idx in sorted_idxs
          ]
  
      for i in range(num_instances):
          color = assigned_colors[i]
          if boxes is not None:
              self.draw_box(boxes[i], edge_color=color)
  
          if labels is not None:
              # first get a box
              if boxes is not None:
                  x0, y0, x1, y1 = boxes[i]
                  text_pos = (
                      x0,
                      y0,
                  )  # if drawing boxes, put text on the box corner.
                  horiz_align = "left"
              else:
                  continue  # drawing the box confidence for keypoints isn't very useful.
              # for small objects, draw text at the side to avoid occlusion
              instance_area = (y1 - y0) * (x1 - x0)
              if (
                  instance_area
                  < _SMALL_OBJECT_AREA_THRESH * self.output.scale
                  or y1 - y0 < 40 * self.output.scale
              ):
                  if y1 >= self.output.height - 5:
                      text_pos = (x1, y0)
                  else:
                      text_pos = (x0, y1)
  
              height_ratio = (y1 - y0) / np.sqrt(
                  self.output.height * self.output.width
              )
              lighter_color = self._change_color_brightness(
                  color, brightness_factor=0.7
              )
              font_size = (
                  np.clip((height_ratio - 0.02) / 0.08 + 1, 1.2, 2)
                  * 0.5
                  * self._default_font_size
              )
              self.draw_text(
                  labels[i],
                  text_pos,
                  color=lighter_color,
                  horizontal_alignment=horiz_align,
                  font_size=font_size,
              )
  
      return self.output
  
imports: import collections
  import colorsys
  import logging
  import re
  from enum import Enum, unique
  from typing import List
  import matplotlib
  import matplotlib.colors
  import matplotlib.figure
  import matplotlib.pyplot
  import numpy
  import pandas
  from matplotlib.backends.backend_agg import FigureCanvasAgg
  from PIL import Image
  from .colormap import random_color
  from .misc import merge_spans
label_desc: Use image node_id 4 for calling the ObjectDetectionVisualizer obj's underlying member method code with example usage: obj.overlay_instances() and returns: self, self