# Predicts left and right hand landmarks within corresponding ROIs derived from
# hand-related pose landmarks.

type: "HandLandmarksLeftAndRightCpu"

# CPU image. (ImageFrame)
input_stream: "IMAGE:input_video"
# Pose landmarks to derive initial hand location from. (NormalizedLandmarkList)
input_stream: "POSE_LANDMARKS:pose_landmarks"

# Left hand landmarks. (NormalizedLandmarkList)
output_stream: "LEFT_HAND_LANDMARKS:left_hand_landmarks"
# RIght hand landmarks. (NormalizedLandmarkList)
output_stream: "RIGHT_HAND_LANDMARKS:right_hand_landmarks"

# Debug outputs.
output_stream: "LEFT_HAND_ROI_FROM_POSE:left_hand_roi_from_pose"
output_stream: "LEFT_HAND_ROI_FROM_RECROP:left_hand_roi_from_recrop"
output_stream: "LEFT_HAND_TRACKING_ROI:left_hand_tracking_roi"
output_stream: "RIGHT_HAND_ROI_FROM_POSE:right_hand_roi_from_pose"
output_stream: "RIGHT_HAND_ROI_FROM_RECROP:right_hand_roi_from_recrop"
output_stream: "RIGHT_HAND_TRACKING_ROI:right_hand_tracking_roi"

# Extracts left-hand-related landmarks from the pose landmarks.
node {
  calculator: "SplitNormalizedLandmarkListCalculator"
  input_stream: "pose_landmarks"
  output_stream: "left_hand_landmarks_from_pose"
  options: {
    [mediapipe.SplitVectorCalculatorOptions.ext] {
      ranges: { begin: 15 end: 16 }
      ranges: { begin: 17 end: 18 }
      ranges: { begin: 19 end: 20 }
      combine_outputs: true
    }
  }
}

# Predicts left hand landmarks.
node {
  calculator: "HandLandmarksFromPoseCpu"
  input_stream: "IMAGE:input_video"
  input_stream: "HAND_LANDMARKS_FROM_POSE:left_hand_landmarks_from_pose"
  output_stream: "HAND_LANDMARKS:left_hand_landmarks"
  # Debug outputs.
  output_stream: "HAND_ROI_FROM_POSE:left_hand_roi_from_pose"
  output_stream: "HAND_ROI_FROM_RECROP:left_hand_roi_from_recrop"
  output_stream: "HAND_TRACKING_ROI:left_hand_tracking_roi"
}

# Extracts right-hand-related landmarks from the pose landmarks.
node {
  calculator: "SplitNormalizedLandmarkListCalculator"
  input_stream: "pose_landmarks"
  output_stream: "right_hand_landmarks_from_pose"
  options: {
    [mediapipe.SplitVectorCalculatorOptions.ext] {
      ranges: { begin: 16 end: 17 }
      ranges: { begin: 18 end: 19 }
      ranges: { begin: 20 end: 21 }
      combine_outputs: true
    }
  }
}

# Extracts right-hand-related landmarks from the pose landmarks.
node {
  calculator: "HandLandmarksFromPoseCpu"
  input_stream: "IMAGE:input_video"
  input_stream: "HAND_LANDMARKS_FROM_POSE:right_hand_landmarks_from_pose"
  output_stream: "HAND_LANDMARKS:right_hand_landmarks"
  # Debug outputs.
  output_stream: "HAND_ROI_FROM_POSE:right_hand_roi_from_pose"
  output_stream: "HAND_ROI_FROM_RECROP:right_hand_roi_from_recrop"
  output_stream: "HAND_TRACKING_ROI:right_hand_tracking_roi"
}
