code: def _annotate_image(pil_image, anns, confidence_threshold):
      from PIL import ImageDraw, ImageFont
  
      draw = ImageDraw.Draw(pil_image)
      font = ImageFont.load_default()
      BUF = 2
  
      # Reverse, to print the highest confidence on top
      for ann in reversed(anns):
          if (
              "confidence" in ann
              and ann["confidence"] < confidence_threshold
          ):
              continue
          if "label" in ann:
              color = COLOR_NAMES[
                  _string_hash(ann["label"]) % len(COLOR_NAMES)
              ]
          else:
              color = "White"
  
          left = (
              ann["coordinates"]["x"] - ann["coordinates"]["width"] / 2
          )
          top = (
              ann["coordinates"]["y"] - ann["coordinates"]["height"] / 2
          )
          right = (
              ann["coordinates"]["x"] + ann["coordinates"]["width"] / 2
          )
          bottom = (
              ann["coordinates"]["y"] + ann["coordinates"]["height"] / 2
          )
  
          draw.line(
              [
                  (left, top),
                  (left, bottom),
                  (right, bottom),
                  (right, top),
                  (left, top),
              ],
              width=4,
              fill=color,
          )
  
          if "confidence" in ann:
              text = "{} {:.0%}".format(ann["label"], ann["confidence"])
          else:
              text = ann["label"]
  
          width, height = font.getsize(text)
  
          if top < height + 2 * BUF:
              label_top = bottom + height + 2 * BUF
          else:
              label_top = top
          draw.rectangle(
              [
                  (left - 1, label_top - height - 2 * BUF),
                  (left + width + 2 * BUF, label_top),
              ],
              fill=color,
          )
  
          draw.text(
              (left + BUF, label_top - height - BUF),
              text,
              fill="black",
              font=font,
          )
  
file_path: turicreate/src/python/turicreate/toolkits/object_detector/util/_visualization.py
imports: from __future__ import print_function
  from __future__ import division
  from __future__ import absolute_import
  import turicreate
  import numpy
  from turicreate.toolkits._internal_utils import _numeric_param_check_range
  from turicreate.toolkits._main import ToolkitError
label_desc: Use image node_id 2 for calling a global function with example usage: _annotate_image(pil_image, anns, confidence_threshold) without return types