code: def visualize_action(
      im,
      mot_boxes,
      action_visual_collector=None,
      action_text="",
      video_action_score=None,
      video_action_text="",
  ):
      im = cv2.imread(im) if isinstance(im, str) else im
      im_h, im_w = im.shape[:2]
  
      text_scale = max(1, im.shape[1] / 400.0)
      text_thickness = 2
  
      if action_visual_collector:
          id_action_dict = {}
          for collector, action_type in zip(
              action_visual_collector, action_text
          ):
              id_detected = collector.get_visualize_ids()
              for pid in id_detected:
                  id_action_dict[pid] = id_action_dict.get(pid, [])
                  id_action_dict[pid].append(action_type)
          for mot_box in mot_boxes:
              # mot_box is a format with [mot_id, class, score, xmin, ymin, w, h]
              if mot_box[0] in id_action_dict:
                  text_position = (
                      int(mot_box[3] + mot_box[5] * 0.75),
                      int(mot_box[4] - 10),
                  )
                  display_text = ", ".join(id_action_dict[mot_box[0]])
                  cv2.putText(
                      im,
                      display_text,
                      text_position,
                      cv2.FONT_HERSHEY_PLAIN,
                      text_scale,
                      (0, 0, 255),
                      2,
                  )
  
      if video_action_score:
          cv2.putText(
              im,
              video_action_text + ": %.2f" % video_action_score,
              (int(im_w / 2), int(15 * text_scale) + 5),
              cv2.FONT_ITALIC,
              text_scale,
              (0, 0, 255),
              thickness=text_thickness,
          )
  
      return im
  
imports: from __future__ import division
  import os
  import cv2
  import math
  import numpy
  import PIL
  from PIL import Image, ImageDraw, ImageFile
label_desc: Use image node_id 10 for calling a global function with example usage: visualize_action(im, mot_boxes, action_visual_collector, action_text, video_action_score, video_action_text) and returns: im