How to detect people in a photo in Javascript

Deep learning has been making rapid advances in recent times, bringing the level of accuracy in photo processing to new heights. Want to set up and train one your system from the ground up? What if there was an easier way? We have a system already calibrated that can be called upon through an API. Believe me, it’s going to save you a ton of time. Here’s how to get started with it.

Import the client with this script tag snippet.

<script src=""></script>

Now call the function for detecting people in photos:

var CloudmersiveImageApiClient = require('cloudmersive-image-api-client');var defaultClient = CloudmersiveImageApiClient.ApiClient.instance;// Configure API key authorization: Apikeyvar Apikey = defaultClient.authentications['Apikey'];Apikey.apiKey = 'YOUR API KEY';// Uncomment the following line to set a prefix for the API key, e.g. "Token" (defaults to null)//Apikey.apiKeyPrefix = 'Token';var apiInstance = new CloudmersiveImageApiClient.RecognizeApi();var imageFile = "/path/to/file"; // File | Image file to perform the operation on.  Common file formats such as PNG, JPEG are supported.var callback = function(error, data, response) {if (error) {console.error(error);} else {console.log('API called successfully. Returned data: ' + data);}};apiInstance.recognizeDetectPeople(imageFile, callback);

That’s it! Pop in an imageFile and let it do its work. We can try it with this image:

Here’s what the API sent back.

"Successful": true,
"Objects": [
"ObjectClassName": "person",
"Height": 1471,
"Width": 1434,
"Score": 0.8946137428283691,
"X": 736,
"Y": 173
"ObjectClassName": "person",
"Height": 1499,
"Width": 2217,
"Score": 0.8725058436393738,
"X": 1284,
"Y": 176
"ObjectClassName": "person",
"Height": 1496,
"Width": 1123,
"Score": 0.7887917160987854,
"X": 17,
"Y": 124
"ObjectCount": 3

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

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store