code: def draw_text(
      draw,
      box: list,
      cls: int,
      score: float,
      category_index: dict,
      color: str,
      font: str = "arial.ttf",
      font_size: int = 24,
  ):
      """
      将目标边界框和类别信息绘制到图片上
      """
      try:
          font = ImageFont.truetype(font, font_size)
      except IOError:
          font = ImageFont.load_default()
  
      left, top, right, bottom = box
      # If the total height of the display strings added to the top of the bounding
      # box exceeds the top of the image, stack the strings below the bounding box
      # instead of above.
      display_str = f"{category_index[str(cls)]}: {int(100 * score)}%"
      display_str_heights = [font.getsize(ds)[1] for ds in display_str]
      # Each display_str has a top and bottom margin of 0.05x.
      display_str_height = (1 + 2 * 0.05) * max(display_str_heights)
  
      if top > display_str_height:
          text_top = top - display_str_height
          text_bottom = top
      else:
          text_top = bottom
          text_bottom = bottom + display_str_height
  
      for ds in display_str:
          text_width, text_height = font.getsize(ds)
          margin = np.ceil(0.05 * text_width)
          draw.rectangle(
              [
                  (left, text_top),
                  (left + text_width + 2 * margin, text_bottom),
              ],
              fill=color,
          )
          draw.text(
              (left + margin, text_top), ds, fill="black", font=font
          )
          left += text_width
  
file_path: deep-learning-for-image-processing/pytorch_object_detection/retinaNet/draw_box_utils.py
imports: from PIL.Image import Image, fromarray
  import PIL.ImageDraw
  import PIL.ImageFont
  from PIL import ImageColor
  import numpy
label_desc: Use image node_id 1 for calling a global function with example usage: draw_text(draw, box, cls, score, category_index, color, font, font_size) without return types