def test_invalid_input_image(self):
   image = np.arange(18, dtype=np.uint8).reshape(3, 3, 2)
   with self.assertRaisesRegex(
       ValueError, 'Input image must contain three channel rgb data.'):
     drawing_utils.draw_landmarks(image, landmark_pb2.NormalizedLandmarkList())
   with self.assertRaisesRegex(
       ValueError, 'Input image must contain three channel rgb data.'):
     drawing_utils.draw_detection(image, detection_pb2.Detection())
   with self.assertRaisesRegex(
       ValueError, 'Input image must contain three channel rgb data.'):
     rotation = np.eye(3, dtype=np.float32)
     translation = np.array([0., 0., 1.])
     drawing_utils.draw_axis(image, rotation, translation)
 def test_draw_axis_zero_translation(self):
   image = np.zeros((100, 100, 3), np.uint8)
   expected_result = np.copy(image)
   origin = (50, 50)
   x_axis = (0, 50)
   y_axis = (50, 100)
   z_axis = (50, 50)
   cv2.arrowedLine(expected_result, origin, x_axis, drawing_utils.RED_COLOR,
                   DEFAULT_AXIS_DRAWING_SPEC.thickness)
   cv2.arrowedLine(expected_result, origin, y_axis, drawing_utils.GREEN_COLOR,
                   DEFAULT_AXIS_DRAWING_SPEC.thickness)
   cv2.arrowedLine(expected_result, origin, z_axis, drawing_utils.BLUE_COLOR,
                   DEFAULT_AXIS_DRAWING_SPEC.thickness)
   rotation = np.eye(3, dtype=np.float32)
   translation = np.zeros((3,), dtype=np.float32)
   drawing_utils.draw_axis(image, rotation, translation)
   np.testing.assert_array_equal(image, expected_result)
 def test_draw_axis(self):
   image = np.zeros((100, 100, 3), np.uint8)
   expected_result = np.copy(image)
   origin = (50, 50)
   x_axis = (75, 50)
   y_axis = (50, 22)
   z_axis = (50, 77)
   cv2.arrowedLine(expected_result, origin, x_axis, drawing_utils.RED_COLOR,
                   DEFAULT_AXIS_DRAWING_SPEC.thickness)
   cv2.arrowedLine(expected_result, origin, y_axis, drawing_utils.GREEN_COLOR,
                   DEFAULT_AXIS_DRAWING_SPEC.thickness)
   cv2.arrowedLine(expected_result, origin, z_axis, drawing_utils.BLUE_COLOR,
                   DEFAULT_AXIS_DRAWING_SPEC.thickness)
   r = np.sqrt(2.) / 2.
   rotation = np.array([[1., 0., 0.], [0., r, -r], [0., r, r]])
   translation = np.array([0, 0, -0.2])
   drawing_utils.draw_axis(image, rotation, translation)
   np.testing.assert_array_equal(image, expected_result)