docstr: Tests pose models on a video.
docstr_tok: ["Tests","pose","models","on","a","video","."]
code: def test_on_video(self, model_complexity, expected_name):
      """Tests pose models on a video."""
      # Set threshold for comparing actual and expected predictions in pixels.
      diff_threshold = 15
      world_diff_threshold = 0.1
  
      video_path = os.path.join(
          os.path.dirname(__file__), "testdata/pose_squats.mp4"
      )
      expected_path = os.path.join(
          os.path.dirname(__file__), "testdata/{}".format(expected_name)
      )
  
      # Predict pose landmarks for each frame.
      video_cap = cv2.VideoCapture(video_path)
      actual_per_frame = []
      actual_world_per_frame = []
      frame_idx = 0
      with mp_pose.Pose(
          static_image_mode=False, model_complexity=model_complexity
      ) as pose:
          while True:
              # Get next frame of the video.
              success, input_frame = video_cap.read()
              if not success:
                  break
  
              # Run pose tracker.
              input_frame = cv2.cvtColor(input_frame, cv2.COLOR_BGR2RGB)
              result = pose.process(image=input_frame)
              pose_landmarks = self._landmarks_list_to_array(
                  result.pose_landmarks, input_frame.shape
              )
              pose_world_landmarks = (
                  self._world_landmarks_list_to_array(
                      result.pose_world_landmarks
                  )
              )
  
              actual_per_frame.append(pose_landmarks)
              actual_world_per_frame.append(pose_world_landmarks)
  
              input_frame = cv2.cvtColor(input_frame, cv2.COLOR_RGB2BGR)
              self._annotate(input_frame, result, frame_idx)
              frame_idx += 1
      actual = np.array(actual_per_frame)
      actual_world = np.array(actual_world_per_frame)
  
      # Dump actual .npz.
      npz_path = self._get_output_path(expected_name)
      np.savez(
          npz_path, predictions=actual, predictions_world=actual_world
      )
  
      # Dump actual JSON.
      json_path = self._get_output_path(
          expected_name.replace(".npz", ".json")
      )
      with open(json_path, "w") as fl:
          dump_data = {
              "predictions": np.around(actual, 3).tolist(),
              "predictions_world": np.around(actual_world, 3).tolist(),
          }
          fl.write(
              json.dumps(dump_data, indent=2, separators=(",", ": "))
          )
  
      # Validate actual vs. expected landmarks.
      expected = np.load(expected_path)["predictions"]
      assert (
          actual.shape == expected.shape
      ), "Unexpected shape of predictions: {} instead of {}".format(
          actual.shape, expected.shape
      )
      self._assert_diff_less(
          actual[..., :2], expected[..., :2], threshold=diff_threshold
      )
  
      # Validate actual vs. expected world landmarks.
      expected_world = np.load(expected_path)["predictions_world"]
      assert (
          actual_world.shape == expected_world.shape
      ), "Unexpected shape of world predictions: {} instead of {}".format(
          actual_world.shape, expected_world.shape
      )
      self._assert_diff_less(
          actual_world, expected_world, threshold=world_diff_threshold
      )
  
imports: import json
  import os
  import tempfile
  from typing import NamedTuple
  from absl.testing import absltest
  from absl.testing import parameterized
  import cv2
  import numpy
  import numpy.testing
  from PIL import Image
  from mediapipe.python.solutions import drawing_styles
  from mediapipe.python.solutions import drawing_utils
  from mediapipe.python.solutions import pose
label_desc: Use image node_id 14 for calling the PoseTest obj's underlying member method code with example usage: obj.test_on_video(model_complexity, expected_name) without return types