# MediaPipe graph to extract 3D transform from face detection for multiple faces.
#
# It is required that "geometry_pipeline_metadata_detection.binarypb" is
# available at
# "mediapipe/modules/face_geometry/data/geometry_pipeline_metadata_detection.binarypb"
# path during execution.
#
# EXAMPLE:
#   node {
#     calculator: "FaceGeometryFromDetection"
#     input_stream: "IMAGE_SIZE:image_size"
#     input_stream: "MULTI_FACE_DETECTION:multi_face_detection"
#     input_side_packet: "ENVIRONMENT:environment"
#     output_stream: "MULTI_FACE_GEOMETRY:multi_face_geometry"
#   }

type: "FaceGeometryFromDetection"

# The size of the input frame. The first element of the pair is the frame width;
# the other one is the frame height.
#
# The face landmarks should have been detected on a frame with the same
# ratio. If used as-is, the resulting face geometry visualization should be
# happening on a frame with the same ratio as well.
#
# (std::pair<int, int>)
input_stream: "IMAGE_SIZE:image_size"

# Collection of detected/predicted faces, each represented as a detection.
# (std::vector<DETECTION>)
input_stream: "MULTI_FACE_DETECTION:multi_face_detection"

# Environment that describes the current virtual scene.
# (face_geometry::Environment)
input_side_packet: "ENVIRONMENT:environment"

# A list of 3D transform data for each detected face.
# (std::vector<face_geometry::FaceGeometry>)
#
# NOTE: the triangular topology of the face meshes is only useful when derived
#       from the 468 face landmarks, not from the 6 face detection landmarks
#       (keypoints). The former don't cover the entire face and this mesh is
#       defined here only to comply with the API. It should be considered as
#       a placeholder and/or for debugging purposes.
#
#       Use the face 3D transform derived from the face detection landmarks
#       (keypoints) for the face pose transformation matrix, not the mesh.
output_stream: "MULTI_FACE_GEOMETRY:multi_face_geometry"

# Begin iterating over a vector of the face detections.
node {
  calculator: "BeginLoopDetectionCalculator"
  input_stream: "ITERABLE:multi_face_detection"
  output_stream: "ITEM:face_detection"
  output_stream: "BATCH_END:detection_timestamp"
}

# Extracts face detection keypoints as a normalized landmarks.
node {
  calculator: "DetectionToLandmarksCalculator"
  input_stream: "DETECTION:face_detection"
  output_stream: "LANDMARKS:face_landmarks"
}

# End iterating over a vector of the face detections and receive a vector of
# face landmark lists as a result.
node {
  calculator: "EndLoopNormalizedLandmarkListVectorCalculator"
  input_stream: "ITEM:face_landmarks"
  input_stream: "BATCH_END:detection_timestamp"
  output_stream: "ITERABLE:multi_face_landmarks"
}

# Extracts face 3D transform for multiple faces from a vector of face detection
# landmark lists.
node {
  calculator: "FaceGeometryPipelineCalculator"
  input_side_packet: "ENVIRONMENT:environment"
  input_stream: "IMAGE_SIZE:image_size"
  input_stream: "MULTI_FACE_LANDMARKS:multi_face_landmarks"
  output_stream: "MULTI_FACE_GEOMETRY:multi_face_geometry"
  options: {
    [mediapipe.FaceGeometryPipelineCalculatorOptions.ext] {
      metadata_path: "mediapipe/modules/face_geometry/data/geometry_pipeline_metadata_detection.binarypb"
    }
  }
}
