feat: realtime face detection for filter overlays

RI
8d ago
+1201-60

Fixes #200

What

  • Add startFaceDetection / stopFaceDetection and faceDetected / faceDetectionError events.
  • Emit normalized face bounds (0 to 1, top-left origin) for overlay placement.
  • Support optional faceDetection on CameraPreview.start().

Why

  • Issue #200 requests realtime face position for Snapchat-style filters.
  • Still-image ML plugins do not cover live preview frames.

How

  • Android: ML Kit face detection on a CameraX ImageAnalysis pipeline (mirrors barcode scanning).
  • iOS: Vision VNDetectFaceRectanglesRequest on the existing video data output.
  • Web: Shape Detection FaceDetector when the browser exposes it.
  • TypeScript API and docgen in src/definitions.ts.

Testing

  • bun run build
  • bun run fmt and bun run lint
  • bun test (includes FaceDetectionJsonMapperTest and face-detection-api.test.ts)

Not Tested

  • On-device filter overlay UX (no physical device in this run).
  • iOS xcodebuild (Linux agent; CI covers iOS).
Open in Web Open in Cursor 

Autofix with [code]smith
Open in [code]smith · Need help on this PR? Tag @codesmith-bot with what you need.

Summary by CodeRabbit

  • New Features
    • Added face detection on Android, iOS, and supported web browsers that expose the FaceDetector API. Detection can be enabled when starting the camera or controlled separately.
    • Face results include normalized bounding boxes and optional tracking IDs. Detection errors are reported through a separate event.
    • Detection runs at a default 100 ms interval, which can be adjusted.
  • Documentation
    • Added face-detection setup, options, events, platform availability, and result details to the API documentation.
  • Tests
    • Added coverage for face-bound normalization and the public face-detection API.