How to Detect Faces in an Image in JavaScript
Face detection is one of the key facets of the overarching face recognition process. This technology has become particularly useful over the past decade, considering how many websites and applications that allow you to upload photos for use. The following API can be used in JavaScript to instantly locate all the faces within an image, which can be helpful with tasks such as metadata entry and captioning.
To use this API, we need to run this command to install the jQuery library:
bower install jquery
After the installation, we simply need to input the image file to perform the operation on into the following code:
var form = new FormData();
form.append("imageFile", fileInput.files[0], "file");var settings = {
"url": "https://api.cloudmersive.com/image/face/locate",
"method": "POST",
"timeout": 0,
"headers": {
"Content-Type": "multipart/form-data",
"Apikey": "YOUR-API-KEY-HERE"
},
"processData": false,
"mimeType": "multipart/form-data",
"contentType": false,
"data": form
};$.ajax(settings).done(function (response) {
console.log(response);
});
The returned response will indicate the number of faces and the quadrant each face is located in. Visit the Cloudmersive website to retriever your API key by registering for a free account; this will provide you with 800 monthly calls across our library of APIs.