def test_invalid_image_shape(self): with mp_holistic.Holistic() as holistic: with self.assertRaisesRegex( ValueError, 'Input image must contain three channel rgb data.'): holistic.process( np.arange(36, dtype=np.uint8).reshape(3, 3, 4))
def test_on_image(self, static_image_mode, model_complexity, num_frames): image_path = os.path.join(os.path.dirname(__file__), 'testdata/holistic.jpg') image = cv2.imread(image_path) with mp_holistic.Holistic( static_image_mode=static_image_mode, model_complexity=model_complexity) as holistic: for idx in range(num_frames): results = holistic.process( cv2.cvtColor(image, cv2.COLOR_BGR2RGB)) self._annotate(image.copy(), results, idx) self._assert_diff_less( self._landmarks_list_to_array(results.pose_landmarks, image.shape), EXPECTED_POSE_LANDMARKS, POSE_DIFF_THRESHOLD) self._assert_diff_less( self._landmarks_list_to_array(results.left_hand_landmarks, image.shape), EXPECTED_LEFT_HAND_LANDMARKS, HAND_DIFF_THRESHOLD) self._assert_diff_less( self._landmarks_list_to_array(results.right_hand_landmarks, image.shape), EXPECTED_RIGHT_HAND_LANDMARKS, HAND_DIFF_THRESHOLD) # TODO: Verify the correctness of the face landmarks. self.assertLen(results.face_landmarks.landmark, 468)
def test_blank_image(self): holistic = mp_holistic.Holistic() image = np.zeros([100, 100, 3], dtype=np.uint8) image.fill(255) results = holistic.process(image) self.assertIsNone(results.pose_landmarks) holistic.close()
def test_full_body_model(self, static_image_mode, num_frames): image_path = os.path.join(os.path.dirname(__file__), 'testdata/pose.jpg') holistic = mp_holistic.Holistic(static_image_mode=static_image_mode) image = cv2.imread(image_path) for _ in range(num_frames): results = holistic.process(cv2.cvtColor(image, cv2.COLOR_BGR2RGB)) self._verify_output_landmarks( results.pose_landmarks, image.shape, 33, EXPECTED_POSE_COORDINATES_PREDICTION, POSE_DIFF_THRESHOLOD) self._verify_output_landmarks( results.left_hand_landmarks, image.shape, 21, EXPECTED_LEFT_HAND_COORDINATES_PREDICTION, HAND_DIFF_THRESHOLOD) self._verify_output_landmarks( results.right_hand_landmarks, image.shape, 21, EXPECTED_RIGHT_HAND_COORDINATES_PREDICTION, HAND_DIFF_THRESHOLOD) # TODO: Verify the correctness of the face landmarks. self.assertLen(results.face_landmarks.landmark, 468) holistic.close()
def test_upper_body_model(self, static_image_mode, num_frames): image_path = os.path.join(os.path.dirname(__file__), 'testdata/pose.jpg') with mp_holistic.Holistic(static_image_mode=static_image_mode, upper_body_only=True) as holistic: image = cv2.imread(image_path) for _ in range(num_frames): results = holistic.process( cv2.cvtColor(image, cv2.COLOR_BGR2RGB)) self._assert_diff_less( self._landmarks_list_to_array(results.pose_landmarks, image.shape), EXPECTED_UPPER_BODY_LANDMARKS, POSE_DIFF_THRESHOLD) self._assert_diff_less( self._landmarks_list_to_array(results.left_hand_landmarks, image.shape), EXPECTED_LEFT_HAND_LANDMARKS, HAND_DIFF_THRESHOLD) self._assert_diff_less( self._landmarks_list_to_array(results.right_hand_landmarks, image.shape), EXPECTED_RIGHT_HAND_LANDMARKS, HAND_DIFF_THRESHOLD) # TODO: Verify the correctness of the face landmarks. self.assertLen(results.face_landmarks.landmark, 468)