FindFaces

FindFaces[image]

attempts to find human faces in image and returns a list of bounding boxes.

FindFaces[image,prop]

returns the specified property prop for each detected face.

FindFaces[image,crit,prop]

finds faces that satisfy the criterion crit.

Details and Options

  • FindFaces returns detected faces as a list of bounding boxes, each given as a Rectangle object.
  • Coordinates {x,y} are assumed to be in the standard image coordinate system.
  • The property prop can be any of the following:
  • "BoundingBox"bounding boxes returned as Rectangle objects
    "BoundingBoxArea"pixel area of each face
    "Image"subimages containing each face
    "Position"the position of each face given as {x,y}
    "Strength"strength of the detected face
    featureany feature available in FacialFeatures
    {prop1,prop2,}a list of properties
  • The criterion crit can be any of the following:
  • {min,max}faces of size min through max in pixels
    {Scaled[amin],Scaled[amax]}faces of relative size amin to amax
    ffaces that satisfy f
  • When a pure function f is used, facial features such as age and gender can be accessed using #Age and #Gender. A face is returned if f returns True.
  • For the complete list of facial features, see the reference page for FacialFeatures.
  • The following options can be given:
  • AcceptanceThresholdAutomaticdetection acceptance threshold
    MaxFeaturesAllnumber of faces to return
    MaxOverlapFractionAutomaticmaximum allowed overlap fraction
    MethodAutomaticmethod to use
    Padding"Fixed"padding scheme to use at image boundaries
    PaddingSize0amount of padding around each detected face
    PerformanceGoal$PerformanceGoalwhat to optimize in the detection
    SortedByAutomaticfunction to use for sorting the result
  • With PaddingSize->x, each detected face is padded by x pixels on each side. Using PaddingSize->Scaled[s], each face is padded by a fraction s of its bounding box.
  • If available, faces are padded with image content. At the boundaries, the setting of Padding is used.
  • By default, detected faces are sorted based on their strength. Use SortedBy->f to specify a different sorting function. The function f can access available properties using the pattern #prop.
  • Possible settings for Method include:
  • "Haar"cascade detector based on Haar features
    "LocalBinaryPatterns"cascade detector based on LBP features
    "SingleShotDetector"neural network detector based on SSD architecture
    {method1,method2,}aggregates the result of all methodi
  • For multichannel images, the "Haar" and "LocalBinaryPatterns" methods operate on grayscale intensities.
  • FindFaces uses machine learning. Its methods, training sets and biases included therein may change and yield varied results in different versions of the Wolfram Language.
  • FindFaces may download resources that will be stored in your local object store at $LocalBase, and that can be listed using LocalObjects[] and removed using ResourceRemove.

Examples

open allclose all

Basic Examples  (2)

Find coordinates of faces in an image:

Extract subimages that include faces:

Detect and highlight a face in an image:

Scope  (7)

Properties  (4)

Compute the face bounding box:

Extract the portion of the image corresponding to the bounding box:

Extract multiple properties:

Extract features available in FacialFeatures:

Criteria  (3)

Use a computable property as a test argument:

Some test results can be used as shortcuts for the whole test:

Find faces of all sizes:

Specify a maximum face size in pixels:

Specify a minimum face size in pixels:

Use Scaled to specify the face size relative to the image dimensions:

Options  (10)

AcceptanceThreshold  (1)

By default, all the detected faces are returned:

Use AcceptanceThresholdt to return only detections with strength greater than t:

MaxFeatures  (1)

By default, all the detected faces are returned:

Use MaxFeaturesn to return only the n strongest detections:

MaxOverlapFraction  (1)

By default, all the detected faces are returned, regardless of their overlapping:

Find only non-overlapping faces:

Specify a maximum overlap threshold:

Method  (2)

FindFaces automatically picks the detection method:

Specify the method to use:

Use the combined result from multiple methods:

The "LocalBinaryPatterns" method is a cascade classifier that works on a histogram of the gradients (HoG) features. It is a very fast and lightweight multiscale method:

The "Haar" method is a cascade classifier working on Haar features. It is more robust than "LocalBinaryPatterns" but generally slower:

The "SingleShotDetector" method is based on a single neural net evaluation, and it is very stable with respect to variations in pose, illumination, occlusion and subjects. It is slower compared to two other methods:

Padding  (1)

The bounding box of a detection can be padded beyond the image boundary:

Specify a custom padding specification:

PaddingSize  (2)

FindFaces by default returns a fairly tight crop around each face:

Specify a padding size to be added around each face:

Specify a negative padding to crop more:

Specify a scaled padding:

Compare detected faces using different paddings:

PerformanceGoal  (1)

Use PerformanceGoal"Quality" to emphasize the quality of the result:

Use PerformanceGoal"Speed" to emphasize the speed of computation:

SortedBy  (1)

By default, detections are sorted by "Strength":

Specify a different property:

Applications  (2)

Find and highlight detected faces:

Find and blur all detected faces:

Dynamic detection of faces:

Properties & Relations  (2)

Faces may be detected in spite of rotation in the image plane:

Faces may be detected in spite of intensity changes:

Possible Issues  (3)

Upright faces are usually better detected:

Other faces may be detected when rotating the image:

Faces turned away from the camera may not be detected:

Very small or low resolution faces may not be detected:

Resampling the image may improve the detection:

Introduced in 2012
 (9.0)
 |
Updated in 2018
 (11.3)
2019
 (12.0)
2020
 (12.1)