FaceDetector.Builder

public static class FaceDetector.Builder extends Object

Builder for creating face detector instances.

Public Constructor Summary

Builder(Context context)
Creates a face detector builder with the supplied context.

Public Method Summary

FaceDetector
build()
Builds a face detector instance.
FaceDetector.Builder
setClassificationType(int classificationType)
Indicates whether to run additional classifiers for characterizing attributes such as "smiling" and "eyes open".
FaceDetector.Builder
setLandmarkType(int landmarkType)
Sets whether to detect no landmarks, all landmarks, or contour landmarks.
FaceDetector.Builder
setMinFaceSize(float proportionalMinFaceSize)
Sets the smallest desired face size, expressed as a proportion of the width of the head to the image width.
FaceDetector.Builder
setMode(int mode)
Extended option for controlling additional accuracy / speed trade-offs in performing face detection.
FaceDetector.Builder
setProminentFaceOnly(boolean prominentFaceOnly)
Indicates whether to detect all faces, or to only detect the most prominent face (i.e., a large face that is most central within the frame).
FaceDetector.Builder
setTrackingEnabled(boolean trackingEnabled)
Enables or disables face tracking, which will maintain a consistent ID for each face when processing consecutive frames.

Inherited Method Summary

Public Constructors

public Builder (Context context)

Creates a face detector builder with the supplied context.

Public Methods

public FaceDetector build ()

Builds a face detector instance.

Note that this method may cause blocking disk reads and should not be called on an application's main thread. To avoid blocking the main thread, consider moving Detector construction to a background thread using AsyncTask. Enable StrictMode to automatically detect blocking operations on the main thread.

public FaceDetector.Builder setClassificationType (int classificationType)

Indicates whether to run additional classifiers for characterizing attributes such as "smiling" and "eyes open". Default: FaceDetector.NO_CLASSIFICATIONS

Parameters
classificationType the subset of classifiers to use. One of FaceDetector.NO_CLASSIFICATIONS or FaceDetector.ALL_CLASSIFICATIONS.
Throws
IllegalArgumentException if classificationType is invalid.

public FaceDetector.Builder setLandmarkType (int landmarkType)

Sets whether to detect no landmarks, all landmarks, or contour landmarks. Processing time increases as the number of landmarks to search for increases, so detecting all landmarks will increase the overall detection time. Detecting landmarks can improve pose estimation. Default: FaceDetector.NO_LANDMARKS

Parameters
landmarkType the type of landmark detector to use. One of FaceDetector.NO_LANDMARKS, FaceDetector.ALL_LANDMARKS, or FaceDetector.CONTOUR_LANDMARKS. Note: FaceDetector.CONTOUR_LANDMARKS are only returned in FaceDetector.SELFIE_MODE.
Throws
IllegalArgumentException if an invalid landmark detector type is provided

public FaceDetector.Builder setMinFaceSize (float proportionalMinFaceSize)

Sets the smallest desired face size, expressed as a proportion of the width of the head to the image width. For example, if a value of 0.1 is specified then the smallest face to search for is roughly 10% of the width of the image being searched.

Setting the min face size is a performance vs. accuracy trade-off: setting the face size smaller will enable the detector to find smaller faces but detection will take longer; setting the face size larger will exclude smaller faces but will run faster.

This is not a hard limit on face size; the detector may find faces slightly smaller than specified.

By default, this value is inferred by the prominentFaceOnly setting. If unspecified, the inferred face size is 0.1 (prominentFaceOnly == false) or 0.35 (prominentFaceOnly == true).

Parameters
proportionalMinFaceSize the smallest head size to search for relative to the size of the image, in the range of 0.0 and 1.0. For example, a setting of 0.5 would indicate that detected faces need to fill at least half of the image width.
Throws
IllegalArgumentException if an invalid proportion is provided

public FaceDetector.Builder setMode (int mode)

Extended option for controlling additional accuracy / speed trade-offs in performing face detection. In general, choosing the more accurate mode will generally result in longer runtime, whereas choosing the faster mode will generally result in detecting fewer faces. Default: FaceDetector.FAST_MODE

Parameters
mode fast/accurate trade-off mode. One of FaceDetector.FAST_MODE or FaceDetector.ACCURATE_MODE.
Throws
IllegalArgumentException if mode is invalid.

public FaceDetector.Builder setProminentFaceOnly (boolean prominentFaceOnly)

Indicates whether to detect all faces, or to only detect the most prominent face (i.e., a large face that is most central within the frame). Default: false

By default, there is no limit in the number of faces detected. Setting this value to true can increase the speed of the detector since the detector does not need to search exhaustively for all faces.

public FaceDetector.Builder setTrackingEnabled (boolean trackingEnabled)

Enables or disables face tracking, which will maintain a consistent ID for each face when processing consecutive frames. Default: true

If your code uses a MultiProcessor or FocusingProcessor instance, tracking must be enabled. Having tracking enabled is also recommended for handling live video.

Tracking should be disabled for handling a series of non-consecutive still images.