Calculating Bounding box for a face on an image

This time we’re using the Bounding box returned by Clarifai’s Face Model API . Google Vision and Amazon Face Detection Rekognition APIs are returning different type of data (x,y,width, height).

Amazon Rekognition:
left = image.width*BoundingBox.Left
top = image.height*BoundingBox.Top

 

Based on the description Face Detection Model’s response on this page https://www.clarifai.com/models/face-detection-image-recognition-model/a403429f2ddf4b49b307e318f00e528b#documentation, we’ll calculate the top-left corner and bottom-right corner.

given original image size 500 width x 333 height, the top-left coordinate of the image is (0.0, 0.0), and the bottom-right of the image is (1.0, 1.0)
Bounding Box:{
“top_row”: 0.22296476,
“left_col”: 0.6717238,
“bottom_row”: 0.33909792,
“right_col”: 0.74911636
}

The calculations are essentially percentages that are measures from the (0,0) top-left corner of the image and you can interpret them as:

The Top Left Corner of the bounding box is 22% from the top and 67% from the Left
The Bottom Right Corner of the bounding box is 33% from the top and 75% from the left

The corresponding “pixel” coordinates of this box would be:

Top Left: (335, 74)
Bottom Right: (375, 110)
Width:40
Height:36

These values (x,y,width,height) are used for client to draw a blur/opacity/solid boxes on faces on a picture.