How to detect faces in photo in Salesforce Apex

Cloudmersive
1 min readFeb 18, 2020

--

Facial detection is the foundation of any good photo app these days, and has wide reaching uses in so much else. I’m guessing you’re not keen to dive into the Deep Learning rabbit hole to set it up from scratch, though. That’s OK, we’ve got a lightning-fast alternative for you.

First, download our API Client. Unzip it and extract the contents to your project folder.

Proceed to call faceLocate.

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>{'imageFile' => Blob.valueOf('Sample text file\nContents')};try {// cross your fingersSwagFaceLocateResponse result = api.faceLocate(params);System.debug(result);} catch (Swagger.ApiException e) {// ...handle your exceptions}

And just like that, you’re all done. Let’s try it out on this example photograph.

Here is our response:

{
"Successful": true,
"Faces": [
{
"LeftX": 1494,
"TopY": 250,
"RightX": 1598,
"BottomY": 353
}
],
"FaceCount": 1,
"ErrorDetails": null
}

--

--

Cloudmersive
Cloudmersive

Written by Cloudmersive

There’s an API for that. Cloudmersive is a leader in Highly Scalable Cloud APIs.

No responses yet