How to detect people in a photo in Node.js

Cloudmersive
2 min readMay 27, 2019

--

For this task, we want to perform people recognition in a photo in Node.js. The first step is to add a reference to the library:

"dependencies": {
"cloudmersive-image-api-client": "^1.1.4"
}

Now all we need to do is call the recognizeDetectPeople method:

var CloudmersiveImageApiClient = require('cloudmersive-image-api-client');
var defaultClient = CloudmersiveImageApiClient.ApiClient.instance;
// Configure API key authorization: Apikey
var Apikey = defaultClient.authentications['Apikey'];
Apikey.apiKey = 'YOUR API KEY';
var apiInstance = new CloudmersiveImageApiClient.RecognizeApi();var imageFile = Buffer.from(fs.readFileSync("C:\\temp\\inputfile").buffer); // 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);

Now we can experiment with some inputs and outputs. For example, for this input:

Here is an example output:

Here are more examples:

That’s it! It is that easy to identify people in photos — even if they are facing away from the camera, or if their face is not visible. It even works if the subject is shrunk down in size and is in the background of the photo.

--

--

Cloudmersive
Cloudmersive

Written by Cloudmersive

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

No responses yet