-
-
Notifications
You must be signed in to change notification settings - Fork 781
Face detection
This library support face detection using camera1 API and camera2. This methods can be used on preview and streaming. If you call it before start preview, it will take no effect.
The limitation of this feature could change depend of device. Few devices only support 1 face limit or directly no support for it.
Also, eyes and mouth points are no parsed because most of device don't support it.
If you device support detect eyes and mouth in camera2 API this mode is selected by the library: https://developer.android.com/reference/android/hardware/camera2/CameraMetadata#STATISTICS_FACE_DETECT_MODE_FULL
With camera1 API you can't configure it and it is selected automatically.
If your device support it you can get point provided by camera1 and camera2 API using faces provided by onGetFaces callback and parse it yourself. If it is not supported, that values will be null.
To start face detection you can use this method:
import android.graphics.Rect;
import com.pedro.encoder.input.video.facedetector.Face;
import com.pedro.encoder.input.video.facedetector.FaceDetectorCallback;
rtmpCamera.enableFaceDetection(new FaceDetectorCallback() {
@Override
public void onGetFaces(@NonNull Face[] faces, @Nullable Rect scaleSensor, int sensorOrientation) {
// provide native info from camera1 face detection api. From faces objects you can obtain, mouth, eyes, bounds and score.
}
});
This is the method to stop face detection:
rtmpCamera.disableFaceDetection();
If you want parse faces results to a valid scale and position for real time filters you can use this:
FaceParsed faceParsed = FaceDetectorUtil.camera1Parse(face, scaleSensor, sensorOrientation,
CameraHelper.getCameraOrientation(context), rtmpCamera.getCameraFacing());