code: def detect_video(
      model, input_file, output_file, fps=30, score_filter=0.6
  ):
      """Takes in a video and produces an output video with object detection
      run on it (i.e. displays boxes around detected objects in real-time).
      Output videos should have the .avi file extension. Note: some apps,
      such as macOS's QuickTime Player, have difficulty viewing these
      output videos. It's recommended that you download and use
      `VLC <https://www.videolan.org/vlc/index.html>`_ if this occurs.
  
  
      :param model: The trained model with which to run object detection.
      :type model: detecto.core.Model
      :param input_file: The path to the input video.
      :type input_file: str
      :param output_file: The name of the output file. Should have a .avi
          file extension.
      :type output_file: str
      :param fps: (Optional) Frames per second of the output video.
          Defaults to 30.
      :type fps: int
      :param score_filter: (Optional) Minimum score required to show a
          prediction. Defaults to 0.6.
      :type score_filter: float
  
      **Example**::
  
          >>> from detecto.core import Model
          >>> from detecto.visualize import detect_video
  
          >>> model = Model.load('model_weights.pth', ['tick', 'gate'])
          >>> detect_video(model, 'input_vid.mp4', 'output_vid.avi', score_filter=0.7)
      """
  
      # Read in the video
      video = cv2.VideoCapture(input_file)
  
      # Video frame dimensions
      frame_width = int(video.get(cv2.CAP_PROP_FRAME_WIDTH))
      frame_height = int(video.get(cv2.CAP_PROP_FRAME_HEIGHT))
  
      # Scale down frames when passing into model for faster speeds
      scaled_size = 800
      scale_down_factor = min(frame_height, frame_width) / scaled_size
  
      # The VideoWriter with which we'll write our video with the boxes and labels
      # Parameters: filename, fourcc, fps, frame_size
      out = cv2.VideoWriter(
          output_file,
          cv2.VideoWriter_fourcc(*"DIVX"),
          fps,
          (frame_width, frame_height),
      )
  
      # Transform to apply on individual frames of the video
      transform_frame = transforms.Compose(
          [  # TODO Issue #16
              transforms.ToPILImage(),
              transforms.Resize(scaled_size),
              transforms.ToTensor(),
              normalize_transform(),
          ]
      )
  
      # Loop through every frame of the video
      while True:
          ret, frame = video.read()
          # Stop the loop when we're done with the video
          if not ret:
              break
  
          # The transformed frame is what we'll feed into our model
          # transformed_frame = transform_frame(frame)
          transformed_frame = frame  # TODO: Issue #16
          predictions = model.predict(transformed_frame)
  
          # Add the top prediction of each class to the frame
          for label, box, score in zip(*predictions):
              if score < score_filter:
                  continue
  
              # Since the predictions are for scaled down frames,
              # we need to increase the box dimensions
              # box *= scale_down_factor  # TODO Issue #16
  
              # Create the box around each object detected
              # Parameters: frame, (start_x, start_y), (end_x, end_y), (r, g, b), thickness
              cv2.rectangle(
                  frame,
                  (box[0], box[1]),
                  (box[2], box[3]),
                  (255, 0, 0),
                  3,
              )
  
              # Write the label and score for the boxes
              # Parameters: frame, text, (start_x, start_y), font, font scale, (r, g, b), thickness
              cv2.putText(
                  frame,
                  "{}: {}".format(label, round(score.item(), 2)),
                  (box[0], box[1] - 10),
                  cv2.FONT_HERSHEY_SIMPLEX,
                  1,
                  (255, 0, 0),
                  3,
              )
  
          # Write this frame to our video file
          out.write(frame)
  
          # If the 'q' key is pressed, break from the loop
          key = cv2.waitKey(1) & 0xFF
          if key == ord("q"):
              break
  
      # When finished, release the video capture and writer objects
      video.release()
      out.release()
  
      # Close all the frames
      cv2.destroyAllWindows()
  
file_path: detecto/detecto/visualize.py
imports: import cv2
  import matplotlib.patches
  import matplotlib.pyplot
  import torch
  from detecto.utils import reverse_normalize, normalize_transform, _is_iterable
  from torchvision import transforms
label_desc: Use image node_id 2 for calling a global function with example usage: detect_video(model, input_file, output_file, fps, score_filter) without return types