Reputation: 347
As per AWS Rekognition document, there are some methods available which I can use to detect the face in image and it returns me response in below format-
"BoundingBox": {
"Width": 0.36868685483932495,
"Height": 0.5219123363494873,
"Left": 0.6035353541374207,
"Top": 0.4302788972854614
},
"Confidence": 99.55957794189453
Is there any way I can use this response and crop original image to capture only face.
Example- Capture photo from passport/DL.
Upvotes: 0
Views: 420
Reputation: 269340
Yes. The BoundingBox
is telling you where the face is within the image, with figures as a percentage.
So, the face width occupies 36% of the image and starts 60% from the left.
The face height occupies 52% of the image, starting 43% from the top.
Therefore, the face is on the lower right side.
You can multiply these figures by the actual image width and height. Let's say that the image is 2000 pixels wide and 1000 pixels tall, the face would be at:
Top-left corner = (2000 x .6, 1000 x .43) = (1200,430)
Bottom-right corner = (2000 x (.60 + .37), 1000 x (.43 + .52)) = (1940,950)
You can use these co-ordinates with a graphics library to extract the face from the original image file (but not from Rekognition, which does not store the original image).
Upvotes: 1