How to compare and match faces in Salesforce Apex
1 min readFeb 20, 2020
Facial comparison is used by for everything from Xbox One’s player recognition system to face unlock for phones. But how can we harness this great tool without all of the hair pulling that comes with Deep Learning? No problem, we’ve got an API for that.
Download the Cloudmersive API client for image processing and proceed to drag the .zip contents into your Apex project’s folder.
Now call faceCompare and provide an inputImage and matchFace:
SwagFaceApi api = new SwagFaceApi();SwagClient client = api.getClient();// Configure API key authorization: ApikeyApiKeyAuth Apikey = (ApiKeyAuth) client.getAuthentication('Apikey');Apikey.setApiKey('YOUR API KEY');Map<String, Object> params = new Map<String, Object>{'inputImage' => Blob.valueOf('Sample text file\nContents'),'matchFace' => Blob.valueOf('Sample text file\nContents')};try {// cross your fingersSwagFaceCompareResponse result = api.faceCompare(params);System.debug(result);} catch (Swagger.ApiException e) {// ...handle your exceptions}
And it’s as simple as that. Here’s an example output so you can see the format.
{
"Successful": true,
"Faces": [
{
"LeftX": 480,
"TopY": 337,
"RightX": 738,
"BottomY": 595,
"HighConfidenceMatch": true,
"MatchScore": 0.7954186797142029
}
],
"FaceCount": 1,
"ErrorDetails": null
}