Face Detection

The face detection API detects faces and returns their coordinates. It functions similarly to the face recognition API except that it does not perform recognition.

Example

const request = require("request")
const fs = require("fs")
image_stream = fs.createReadStream("family.jpg")
var form = {"image":image_stream}
request.post({url:"http://localhost:80/v1/vision/face", formData:form},function(err,res,body){
response = JSON.parse(body)
predictions = response["predictions"]
console.log(response)
})

Response

{ success: true,
predictions:
[ { confidence: 0.99990666,
y_min: 145,
x_min: 626,
y_max: 261,
x_max: 712 },
{ confidence: 0.99986553,
y_min: 174,
x_min: 543,
y_max: 288,
x_max: 620 },
{ confidence: 0.99986434,
y_min: 163,
x_min: 731,
y_max: 242,
x_max: 810 },
{ confidence: 0.99899536,
y_min: 197,
x_min: 477,
y_max: 279,
x_max: 542 } ] }

Using the face coordinates, we shall use the Easy Image library to extract the faces and save them

const request = require("request")
const fs = require("fs")
const easyimage = require("easyimage")
image_stream = fs.createReadStream("family.jpg")
var form = {"image":image_stream}
request.post({url:"http://localhost:80/v1/vision/face", formData:form},function(err,res,body){
response = JSON.parse(body)
predictions = response["predictions"]
for(var i =0; i < predictions.length; i++){
pred = predictions[i]
gender = pred["gender"]
y_min = pred["y_min"]
x_min = pred["x_min"]
y_max = pred["y_max"]
x_max = pred["x_max"]
easyimage.crop(
{
src: "family.jpg",
dst: i.toString() + "_.jpg",
x: x_min,
cropwidth: x_max - x_min,
y: y_min,
cropheight: y_max - y_min,
}
)
}
})