Skip to content
Husayn Hakeem edited this page Mar 18, 2019 · 2 revisions

What is Face Detector?

Face detector is a face detection Android library which can be easily plugged into any camera API (given it provides a way to process its frames).

Face detector is built on top of Firebase ML Kit's face detection API.

Example of using Face Detector

Your xml layout:

<io.fotoapparat.view.CameraView
    android:id="@+id/cameraView"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <!--Optionally add tap to focus-->
    <io.fotoapparat.view.FocusView
        android:id="@+id/focusView"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

    <husaynhakeem.io.facedetector.FaceBoundsOverlay
        android:id="@+id/facesBoundsOverlay"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />
</io.fotoapparat.view.CameraView>

Your Java file:

FaceBoundsOverlay faceBoundsOverlay = findViewById(R.id.facesBoundsOverlay);
husaynhakeem.io.facedetector.FaceDetector faceDetector = new husaynhakeem.io.facedetector.FaceDetector(faceBoundsOverlay);

cameraView = findViewById(R.id.cameraView);
focusView = findViewById(R.id.focusView); 

fotoapparat = Fotoapparat
                .with(this)
                .into(cameraView)
                .frameProcessor(new Custom2FrameProcessor())
                .focusView(focusView)
               ...
   
private class Custom2FrameProcessor implements FrameProcessor {
    @Override
    public void process(@NonNull Frame frame) {
        husaynhakeem.io.facedetector.models.Frame frame1 = new husaynhakeem.io.facedetector.models.Frame(
            frame.getImage(),
            frame.getRotation(),
            new Size(frame.getSize().width, frame.getSize().height),
            17,
            false);

        faceDetector.process(frame1);
    }
}
Clone this wiki locally