# Converts face-related pose landmarks to re-crop ROI.

type: "FaceLandmarksFromPoseToRecropRoi"

# Face-related pose landmarks (There should be 11 of them).
# (NormalizedLandmarkList)
input_stream: "FACE_LANDMARKS_FROM_POSE:face_landmarks_from_pose"
# Image size (width & height). (std::pair<int, int>)
input_stream: "IMAGE_SIZE:image_size"

# ROI to be used for face detection. (NormalizedRect)
output_stream: "ROI:roi"

# Converts face-related pose landmarks to a detection that tightly encloses all
# landmarks.
node {
  calculator: "LandmarksToDetectionCalculator"
  input_stream: "NORM_LANDMARKS:face_landmarks_from_pose"
  output_stream: "DETECTION:pose_face_detection"
}

# Converts face detection to a normalized face rectangle.
node {
  calculator: "DetectionsToRectsCalculator"
  input_stream: "DETECTION:pose_face_detection"
  input_stream: "IMAGE_SIZE:image_size"
  output_stream: "NORM_RECT:pose_face_rect"
  options: {
    [mediapipe.DetectionsToRectsCalculatorOptions.ext] {
      rotation_vector_start_keypoint_index: 5  # Right eye.
      rotation_vector_end_keypoint_index: 2  # Left eye.
      rotation_vector_target_angle_degrees: 0
    }
  }
}

# Expands face rectangle so that it becomes big enough for face detector to
# localize it accurately.
node {
  calculator: "RectTransformationCalculator"
  input_stream: "NORM_RECT:pose_face_rect"
  input_stream: "IMAGE_SIZE:image_size"
  output_stream: "roi"
  options: {
    [mediapipe.RectTransformationCalculatorOptions.ext] {
      scale_x: 3.0
      scale_y: 3.0
      square_long: true
    }
  }
}
