Live face verification captures the user’s selfie for facial verification or any other purposes, after verifying the user’s physical presence in front of the device camera. The verification is returned in a Selfie object.

SCLiveFaceVerifier uses FirebaseVisionFaseDetector by default to find faces in the image. If you prefer to use another face detection library, you can wrap it in SCFaceDetector (extend abstract SCFaceDetector) and pass it to the bundle. In the wrapper, the resulting face objects must be converted to SCFace when extending SCFaceDetector.

Starting live face verification

To start live face verification:

Creating a bundle with arguments

Use coding similar to this:

Bundle bundle = new LFVBundle.Builder()
                // --- Optional ---
                .setVerificationTimeInMillis(2000)
                .setAccuracy(SCLiveFaceVerificationAccuracy.low)
                .setVerificationSteps(SCLiveFaceVerificationStep.lfv_smile, SCLiveFaceVerificationStep.lfv_straight_face)
                // ----------------
                .create();

Using live face verification from a FragmentActivity

Use coding similar to this:

void captureSelfie() {
    Intent intent = new Intent(this, LiveFaceVerificationActivity.class);
    intent.putExtras(bundle);
    startActivityForResult(intent, LFV_REQUEST_CODE);
}

@Override
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if (requestCode == LFV_REQUEST_CODE && data != null) {
        if (resultCode == RESULT_OK) {
            final Selfie bitmap = LFVBundle.getResultSelfie(data.getExtras());
            // Use Selfie here
        } else if (resultCode == RESULT_CANCELED) {
            // Cancelled
        }
    }
}

Using live face verification from a Fragment

Use coding similar to this:

void captureSelfie() {
    LiveFaceVerificationDialogFragment.start(this, bundle, new LiveFaceVerificationListener() {
        @Override
        public void onComplete(@NonNull Bundle bundle) {
            final Selfie selfie = LiveFaceVerificationActivity.LFVBundle.getResultSelfie(bundle);
            // Use Selfie here
        }

        @Override
        public void onCancelled() {
            // Cancelled
        }
    });
}