feedFrame method

void feedFrame(
  1. HandLandmarkFrame frame
)

Feeds one frame of raw landmarks from the camera ML pipeline.

Implementation

void feedFrame(HandLandmarkFrame frame) {
  if (frame.confidence < minConfidence) return;
  if (frame.landmarks.length < 21) return;

  final hand = frame.hand;
  _lastFrameTime[hand] = frame.timestamp;

  final filters = _filters.putIfAbsent(
    hand,
    () => List.generate(21, (_) => OneEuroFilter()),
  );

  // Reproject normalized image coordinates into metric tracking space and
  // smooth each landmark independently.
  final metric = List<Vector3>.generate(21, (i) {
    final p = frame.landmarks[i];
    final projected = Vector3(
      (p.x - 0.5) * volumeWidth,
      -(p.y - 0.5) * volumeHeight,
      -(baseDistance + p.z * depthScale),
    );
    return filters[i].filter(projected, frame.timestamp);
  });

  final state = hands[hand]!;
  MediaPipeHandDriver.updateHandFromLandmarks(state, metric);
  onHandUpdated?.call(hand, state);
}