Detect faces in images
🤖/image/facedetect detects faces in images and can return either their coordinates or the faces themselves as new images.
You can specify padding around the extracted faces, tailoring the output for your needs.
This Robot works well together with 🤖/image/resize to bring the full power of resized and optimized images to your website or app.
How to improve the accuracy:
- Ensure that your pictures have the correct orientation. This Robot achieves the best performance when the faces in the image are oriented upright and not rotated.
- If the Robot detects objects other than a face, you can use
"faces": "max-confidence"
within your Template for selecting only the detection with the highest confidence. - The number of returned detections can also be controlled using the
min_confidence
parameter. Increasing its value will yield less results but each with a higher confidence. Decreasing the value, on the other hand, will provide more results but may also include objects other than faces.
Usage example
Detect all faces in uploaded images, crop them, and save as separate images:
{
"steps": {
"faces_detected": {
"robot": "/image/facedetect",
"use": ":original",
"crop": true,
"faces": "each",
"crop_padding": "10px"
}
}
}
Parameters
-
use
String / Array of Strings / Object requiredSpecifies which Step(s) to use as input.
-
You can pick any names for Steps except
":original"
(reserved for user uploads handled by Transloadit) -
You can provide several Steps as input with arrays:
"use": [ ":original", "encoded", "resized" ]
💡 That’s likely all you need to know about
use
, but you can view Advanced use cases. -
-
provider
StringWhich AI provider to leverage.
Transloadit outsources this task and abstracts the interface so you can expect the same data structures, but different latencies and information being returned. Different cloud vendors have different areas they shine in, and we recommend to try out and see what yields the best results for your use case.
-
crop
Boolean ⋅ default:false
Determine if the detected faces should be extracted. If this option is set to
false
, then the Robot returns the input image again, but with the coordinates of all detected faces attached tofile.meta.faces
in the result JSON. If this parameter is set totrue
, the Robot will output all detected faces as images. -
crop_padding
String ⋅ default:"5px"
Specifies how much padding is added to the extracted face images if
crop
is set totrue
. Values can be inpx
(pixels) or%
(percentage of the width and height of the particular face image). -
format
String ⋅ default:"preserve"
Determines the output format of the extracted face images if
crop
is set totrue
.The default value
"preserve"
means that the input image format is re-used. format is re-used. Valid values are"jpg"
,"png"
,"tiff"
and"preserve"
. -
min_confidence
Integer(0
-100
) ⋅ default:70
Specifies the minimum confidence that a detected face must have. Only faces which have a higher confidence value than this threshold will be included in the result.
-
faces
String / Integer ⋅ default:"each"
Determines which of the detected faces should be returned. Valid values are:
"each"
— each face is returned individually."max-confidence"
— only the face with the highest confidence value is returned."max-size"
— only the face with the largest area is returned."group"
— all detected faces are grouped together into one rectangle that contains all faces.- any integer — the faces are sorted by their top-left corner and the integer determines the index of the returned face. Be aware the values are zero-indexed, meaning that
faces: 0
will return the first face. If no face for a given index exists, no output is produced.
For the following examples, the input image is:
faces: "each"
applied:
faces: "max-confidence"
applied:
faces: "max-size"
applied:
faces: "group"
applied:
faces: 0
applied:
Demos
Related blog posts
- Launching face detection Robot for images February 5, 2016
- New pricing model for future Transloadit customers February 7, 2018
- Exploring the new 'faces' parameter in image face detection October 25, 2019
- Export files to DigitalOcean Spaces with ease December 9, 2019
- Tech preview: new AI Robots for enhanced media processing February 17, 2020
- Celebrating transloadit’s 2021 milestones and progress January 31, 2022
- Smart CDN enhanced with AI-powered face detection June 21, 2022
- Transloadit's 2022 milestones: growth & innovations February 7, 2023
- How to blur faces in photos with Transloadit July 4, 2023
- Introducing text extraction from PDFs with AI Robot November 9, 2023