How to detect people in a photo in Node.js

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) {
} 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:

Image for post

Here is an example output:

Image for post

Here are more examples:

Image for post
Image for post
Image for post

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.

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