
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
output_meta
Record<string, boolean> | boolean
Allows you to specify a set of metadata that is more expensive on CPU power to calculate, and thus is disabled by default to keep your Assemblies processing fast.
For images, you can add
"has_transparency": true
in this object to extract if the image contains transparent parts and"dominant_colors": true
to extract an array of hexadecimal color codes from the image.For videos, you can add the
"colorspace: true"
parameter to extract the colorspace of the output video.For audio, you can add
"mean_volume": true
to get a single value representing the mean average volume of the audio file.You can also set this to
false
to skip metadata extraction and speed up transcoding.result
boolean
(default:false
)Whether the results of this Step should be present in the Assembly Status JSON
queue
"batch"
Setting the queue to 'batch', manually downgrades the priority of jobs for this step to avoid consuming Priority job slots for jobs that don't need zero queue waiting times
force_accept
boolean
(default:false
)Force a Robot to accept a file type it would have ignored.
By default Robots ignore files they are not familiar with. 🤖/video/encode, for example, will happily ignore input images.
With the force_accept parameter set to true you can force Robots to accept all files thrown at them. This will typically lead to errors and should only be used for debugging or combatting edge cases.
use
string | Array<string> | Array<object> | object
Specifies 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" ] }
Tip
That’s likely all you need to know about
use
, but you can view Advanced use cases.- You can pick any names for Steps except
provider
Which 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
(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.min_confidence
string | number
(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 | number
(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
- New pricing model for future Transloadit customers
- Exploring the new 'faces' parameter in image face detection
- Export files to DigitalOcean Spaces with ease
- Tech preview: new AI Robots for enhanced media processing
- Celebrating transloadit’s 2021 milestones and progress
- Smart CDN enhanced with AI-powered face detection
- Transloadit's 2022 milestones: growth & innovations
- How to blur faces in photos with Transloadit
- Introducing text extraction from PDFs with AI Robot