Facial Comparison

Configuration

To use any Sybrin SDK you will need a Sybrin issued license. You can have a look at our licensing page to request a license.

Using the license provided you will need to build and instance of the SybrinFacialComparisonConfiguration class that will help with configuring the SDKs' behavior.

For example:

SybrinFacialComparisonConfiguration sfcc = new SybrinFacialComparisonConfiguration
        .Builder(<sybrin_license_here>)
        .build();

To see the full range of configuration available please visit the SybrinFacialComparisonConfiguration page

Calling feature

To start the facial comparison process you will need to get an instance of the SybrinFacialComparison class using the configuration built earlier. With this object you will be able to call the compareFaces method. This method requires two parameters. The target, the bitmap that contains the face you wish to run comparison on, and an array of faces, a bitmap array containing faces that the target will be compared to. For a visual understanding refer to the below figure.

Finally you can register for the 2 different callbacks right on the method call.

For example:

Bitmap target = getTargetImage();
Bitmap[] faces = getFaces();

SybrinFacialComparison sfc = SybrinFacialComparison.getInstance(Activity.this, sfcc);
 
sfc.compareFaces(target, faces)
        .addOnSuccessListener(new FacialComparator.OnSuccessListener<FacialComparisonModel>() {
            @Override
            public void onSuccess(FacialComparisonModel result) {
                // Handle success
            }
        })
        .addOnFailureListener(new FacialComparator.OnFailureListener() {
            @Override
             public void onFailure(FacialComparisonException fce) {
                // Handle failure
            }
        });

Subscribing to any of the callbacks on the compareFaces method is optional.

Handling callback responses

There are 2 different callbacks that can be subscribed to. They are as follows:

OnSuccessListener

When the SDK has completed the facial comparison process the result will be posted to the OnSuccessListener.onSuccess callback. The FacialComparisonModel is returned as a result. To get the comparison results you can use the getFaceResults method which will return a list of FacialComarisonResult.

For example:

sfc.compareFaces(target, faces)
        .addOnSuccessListener(new FacialComparator.OnSuccessListener<FacialComparisonModel>() {
            @Override
            public void onSuccess(FacialComparisonModel result) {
            
                // Handle success
                List<FacialComparisonResult> comparisonResult = result.getFaceResults();
            }
        });

OnFailureListener

When the SDK encounters an error a FacialComparisonException is posted to the OnFailureListener.onFailure callback. The FacialComparisonException will contain all the needed information to help solve the issue causing the error.

For example:

sfc.compareFaces(target, faces)
        .addOnFailureListener(new FacialComparator.OnFailureListener() {
            @Override
             public void onFailure(FacialComparisonException fce) {
            
                // Get error message
                String error = fce.getLocalizedMessage();
            }
        });

If you would like to report a bug, contact us!

Full example

Activity.java
SybrinFacialComparisonConfiguration sfcc = new SybrinFacialComparisonConfiguration
        .Builder(<sybrin_license_here>)
        .build();
        
Bitmap target = getTargetImage();
Bitmap[] faces = getFaces();

SybrinFacialComparison sfc = SybrinFacialComparison.getInstance(Activity.this, sfcc);
 
sfc.compareFaces(target, faces)
        .addOnSuccessListener(new FacialComparator.OnSuccessListener<FacialComparisonModel>() {
            @Override
            public void onSuccess(FacialComparisonModel result) {
            
                // Handle success
                List<FacialComparisonResult> comparisonResult = result.getFaceResults();
            }
        })
        .addOnFailureListener(new FacialComparator.OnFailureListener() {
            @Override
             public void onFailure(FacialComparisonException fce) {
            
                // Get error message
                String error = fce.getLocalizedMessage();
            }
        });

Last updated