How to detect people in a photo in Salesforce Apex

Cloudmersive
1 min readFeb 20, 2020

--

What’s a photo app without the ability to detect people autonomously? Today we are going to tackle a method for applying this feature. Don’t worry, this is going to be super easy.

Download our API client and copy the /client folder into the directory of your Apex project.

Now we can implement the recognizeDetectPeople function, like this:

SwagRecognizeApi api = new SwagRecognizeApi();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 fingersSwagObjectDetectionResult result = api.recognizeDetectPeople(params);System.debug(result);} catch (Swagger.ApiException e) {// ...handle your exceptions}

Pretty easy, huh? Let’s give it a quick shot with this photo.

Our result from this photo:

{
"Successful": true,
"Objects": [
{
"ObjectClassName": "person",
"Height": 1279,
"Width": 1361,
"Score": 0.8737415075302124,
"X": 772,
"Y": 162
},
{
"ObjectClassName": "person",
"Height": 1481,
"Width": 2167,
"Score": 0.8343223333358765,
"X": 916,
"Y": 18
}
],
"ObjectCount": 2
}

--

--

Cloudmersive
Cloudmersive

Written by Cloudmersive

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

No responses yet