Skip to content

✨ Support Camera2 native face detection on Android #4174

Description

@mrousavy

Prerequisites

What problem are you trying to solve?

Android face detection currently needs ML Kit and a pixel stream even though Camera2 can return native face metadata with each capture result.

Proposed API / solution

Keep the existing ObjectOutput API:

const faces = useObjectOutput({
  types: ['face'],
  onObjectsScanned,
})

<Camera outputs={[faces]} {...props} />

Internally, allow a metadata output to contribute session configuration without owning a CameraX UseCase. CameraX 1.7 can configure the shared session:

SessionConfig.Builder(useCases)
  .camera2Interop {
    setCaptureRequestOption(
      CaptureRequest.STATISTICS_FACE_DETECT_MODE,
      bestSupportedMode,
    )
    setRepeatingCaptureCallback(
      executor,
      object : CameraCaptureSession.CaptureCallback() {
        override fun onCaptureCompleted(
          session: CameraCaptureSession,
          request: CaptureRequest,
          result: TotalCaptureResult,
        ) {
          emit(result[CaptureResult.STATISTICS_FACES].orEmpty())
        }
      },
    )
  }
  .build()

Prefer FULL, fall back to SIMPLE, and disable it when only OFF is available.

Alternatives considered

ML Kit via a FrameOutput. It is more capable, but needs another stream and app-side inference.

Platforms this should target

Android

Would you be willing to contribute this?

Yes - I'd like to open a PR.

Additional context

  • STATISTICS_FACE_DETECT_MODE, STATISTICS_FACES, and Face
  • API 21+, but support is per camera. Only OFF is guaranteed. Android 17 performance-class 34/35/37 primary cameras must expose SIMPLE or FULL.
  • SIMPLE gives bounds and score. FULL adds an ID and optional eye/mouth points. Camera2 has no yaw/roll, so use faceID = -1 where unsupported and set the angle flags to false.
  • Bounds are sensor active-array coordinates. Normalize crop, zoom, rotation, and mirroring into VisionCamera camera-space; PreviewView.getSensorToViewTransform() handles view mapping.
  • ML Kit documents about 60 ms on Pixel 3 in FAST mode. There is no comparable Camera2 latency or power figure. Avoiding ImageAnalysis, YUV delivery, and app-side inference should reduce app CPU and memory bandwidth, but needs device benchmarks.

Submission

  • I described the problem, not just the solution.
  • I wrote this request in my own words. I did not paste AI-generated proposals.

Metadata

Metadata

Assignees

No one assigned

    Labels

    ✨ featureProposes a new feature or enhancement🤖 androidIssue affects the Android platform

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions