husaynhakeem / android-face-detector

A real-time face detection Android library
MIT License
477 stars 79 forks source link

Using with fotoapparat #3

Closed scognito closed 5 years ago

scognito commented 5 years ago

Hi. This is not an issue, but an help for people like me who want to use it with Fotoapparat.

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>`

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);
        }
    }
husaynhakeem commented 5 years ago

Thanks @scognito. I added it to this project's wiki.