Face-detection based transformations
Uploadcare allows you to use face recognition algorithms to make transformations based on detected faces in an image.
In the most popular use cases, such as creating user pics, blurring faces and cropping based on detected faces, and overlaying text or special things on specified facial attributes, face-based transformations are used in combination with other image processing operations.
List of face-detection based processing operations
Face-detection based cropping
Cropping by faces
Crops the image to the object specified by the :tag
parameter with :face
value — the largest detected face in the image is used as a crop basis.
There are several ways to crop a file:
-/crop/face/3:3/ | -/crop/1:1/50p,30p/ | -/crop/face/200px200p/ |
Keeping proportions
If you want to keep the proportions but fill the entire tile, use -/smart_resize/
to generate missing parts of the picture.
-/smart_resize/250x250/ |
Create a user’s pic
If you want to create a circular user profile photo, combine the operations
-/crop/face/
and -/border_radius/
.
-/crop/face/200px200p/-/crop/1:1/50p,30p/-/border_radius/50p/ |
You can also create a circular user photo, combine the operations -/scale_crop/
and -/border_radius/
.
-/scale_crop/440x440/smart/-/border_radius/50p/ |
Filling an empty area
If you have an empty space when creating a user’s pic, you can fill
it using the -/setfill/:color/
operation.
You can find out the required fill color with the
-/main_colors/
operation
or through other external apps.
Original | Crop image | Fill empty area |
Blur faces
If you need to blur faces in photos to comply with privacy laws,
apply a blur effect to automatically detect faces in the image
using the -/blur_region/faces/
operation.
You can adjust the strength of the blur effect.
It determines with an optional additional strength
value,
ranging to 5000 (default: 10).
For example, -/blur_region/faces/100/
uses a small blur effect with
a strength of 100:
-/blur_region/faces/100/ |
You can “bake in” the applied changes and create a new file that can no longer be reverted to its original state.
Coordinates of facial landmarks
/:uuid/detect_faces/
The detect_faces
operation returns the coordinates of faces found in an
input image. The output is similar to the json
operation. The output is a JSON with the additional list of faces
that
holds the coordinates of faces that were detected.
Data for each of the found faces are put into separate lists that look like this:
Further, lists within faces
contain:
x
,y
— coordinates of the upper-left corner of an area where a face was found.x_size
,y_size
— dimensions of that area.
Note, detect_faces
is not divided from a file UUID by the /-/
separator.
Hence, it can not be piped to other operations.
Run a face-check for the following image on our CDN:
Put detect_faces
into the image URL, separating it with
the forward slash /
from the UUID:
Get the following faces
list in the response JSON:
detect_faces
uses an algorithm that better detects the fronts of faces rather
than facial profiles. Also, covering important face features with
different objects leads to a decline in detection accuracy.
Technically, the operation detects faces using Haar Cascades. That approach deals with machine learning processes that rely on classifiers holding cascades of features specific to faces, eyes, etc.
Position overlays avoiding detected faces
You can combine text overlay
and -/detect_faces/
operations to add text to an image while
avoiding text overlapping with faces.
|