margelo / margelo/react-native-vision-camera
✨ Support Camera2 native face detection on Android
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 9.6k
- Forks
- 1.4k
- Avg merge
- 1d 28m
- Merged PRs (30d)
- 4
Description
Prerequisites
- I have searched existing issues for a similar request.
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, andFace- API 21+, but support is per camera. Only
OFFis guaranteed. Android 17 performance-class 34/35/37 primary cameras must exposeSIMPLEorFULL. SIMPLEgives bounds and score.FULLadds an ID and optional eye/mouth points. Camera2 has no yaw/roll, so usefaceID = -1where 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.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by locating the existing ObjectOutput implementation and Android camera session configuration, then trace how outputs contribute to the shared CameraX session. Use the proposed Camera2 capture metadata and face-detection modes as the behavioral guide. Done means native face metadata reaches the existing API with FULL/SIMPLE fallback and the documented coordinate and unsupported-angle behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- android, kotlin, react-native, typescript
- Domain
- computer-vision, mobile
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100