code: def draw_bbox(image, im_id, catid2name, bboxes, threshold):
      """
      Draw bbox on image
      """
      font_url = "https://paddledet.bj.bcebos.com/simfang.ttf"
      font_path, _ = get_path(font_url, "~/.cache/paddle/")
      font_size = 18
      font = ImageFont.truetype(font_path, font_size, encoding="utf-8")
  
      draw = ImageDraw.Draw(image)
  
      catid2color = {}
      color_list = colormap(rgb=True)[:40]
      for dt in np.array(bboxes):
          if im_id != dt["image_id"]:
              continue
          catid, bbox, score = (
              dt["category_id"],
              dt["bbox"],
              dt["score"],
          )
          if score < threshold:
              continue
  
          if catid not in catid2color:
              idx = np.random.randint(len(color_list))
              catid2color[catid] = color_list[idx]
          color = tuple(catid2color[catid])
  
          # draw bbox
          if len(bbox) == 4:
              # draw bbox
              xmin, ymin, w, h = bbox
              xmax = xmin + w
              ymax = ymin + h
              draw.line(
                  [
                      (xmin, ymin),
                      (xmin, ymax),
                      (xmax, ymax),
                      (xmax, ymin),
                      (xmin, ymin),
                  ],
                  width=2,
                  fill=color,
              )
          elif len(bbox) == 8:
              x1, y1, x2, y2, x3, y3, x4, y4 = bbox
              draw.line(
                  [(x1, y1), (x2, y2), (x3, y3), (x4, y4), (x1, y1)],
                  width=2,
                  fill=color,
              )
              xmin = min(x1, x2, x3, x4)
              ymin = min(y1, y2, y3, y4)
          else:
              logger.error(
                  "the shape of bbox must be [M, 4] or [M, 8]!"
              )
  
          # draw label
          text = "{} {:.2f}".format(catid2name[catid], score)
          tw, th = imagedraw_textsize_c(draw, text, font=font)
          draw.rectangle(
              [(xmin + 1, ymin - th), (xmin + tw + 1, ymin)], fill=color
          )
          draw.text(
              (xmin + 1, ymin - th),
              text,
              fill=(255, 255, 255),
              font=font,
          )
  
      return image
  
file_path: PaddleDetection/ppdet/utils/visualizer.py
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  from __future__ import unicode_literals
  import os
  import numpy
  from PIL import Image, ImageDraw, ImageFont
  import cv2
  import math
  from .colormap import colormap
  from ppdet.utils.logger import setup_logger
  from ppdet.utils.compact import imagedraw_textsize_c
  from ppdet.utils.download import get_path
label_desc: Use image node_id 3 for calling a global function with example usage: draw_bbox(image, im_id, catid2name, bboxes, threshold) and returns: image