# FaceDetector

public interface **FaceDetector** extends [Detector](https://developers.google.com/android/reference/com/google/mlkit/vision/interfaces/Detector.md.txt)\<[List](https://developer.android.com/reference/java/util/List.html)\<[Face](https://developers.google.com/android/reference/com/google/mlkit/vision/face/Face.md.txt)\>\>, [OptionalModuleApi](https://developers.google.com/android/reference/com/google/android/gms/common/api/OptionalModuleApi.md.txt) A `FaceDetection`
client for finding `Face`s in a supplied
image.

A `FaceDetector`
is created via `
FaceDetection.getClient(FaceDetectorOptions)` or `FaceDetection.getClient()`,
if you wish to use the default options. For example, the code below creates a face detector
client with default options.

    FaceDetector faceDetector = FaceDetection.getClient();
     
To perform face detection in an image, you first need to create an instance of `
InputImage` from a `Bitmap`, `ByteBuffer`, `Image` etc. See `InputImage` documentation for more details. For example, the code below creates an `InputImage` from a `Bitmap`.

    InputImage image = InputImage.fromBitmap(bitmap, rotationDegrees);
     
Then the code below can detect faces in the supplied `InputImage`.

    Task<List<Face>> task = faceDetector.process(image);
     task.addOnSuccessListener(...).addOnFailureListener(...);
     
### Public Method Summary

|---|---|
| abstract void | [close](https://developers.google.com/android/reference/com/google/mlkit/vision/face/FaceDetector.md.txt#close())() Closes the detector and releases its resources. |
| abstract Task\<[List](https://developer.android.com/reference/java/util/List.html)\<[Face](https://developers.google.com/android/reference/com/google/mlkit/vision/face/Face.md.txt)\>\> | [process](https://developers.google.com/android/reference/com/google/mlkit/vision/face/FaceDetector.md.txt#process(com.google.android.odml.image.MlImage))([MlImage](https://developers.google.com/android/reference/com/google/android/odml/image/MlImage.md.txt) image) Detects human faces from the supplied image. |
| abstract Task\<[List](https://developer.android.com/reference/java/util/List.html)\<[Face](https://developers.google.com/android/reference/com/google/mlkit/vision/face/Face.md.txt)\>\> | [process](https://developers.google.com/android/reference/com/google/mlkit/vision/face/FaceDetector.md.txt#process(com.google.mlkit.vision.common.InputImage))([InputImage](https://developers.google.com/android/reference/com/google/mlkit/vision/common/InputImage.md.txt) image) Detects human faces from the supplied image. |

### Inherited Method Summary

From interface java.io.Closeable

|---|---|
| abstract void | close() |

From interface java.lang.AutoCloseable

|---|---|
| abstract void | close() |

## Public Methods

#### public abstract void **close** ()

Closes the detector and releases its resources.

#### public abstract Task\<[List](https://developer.android.com/reference/java/util/List.html)\<[Face](https://developers.google.com/android/reference/com/google/mlkit/vision/face/Face.md.txt)\>\>
**process** ([MlImage](https://developers.google.com/android/reference/com/google/android/odml/image/MlImage.md.txt) image)

Detects human faces from the supplied image.

This is an experimental API in beta version.

Create an `MlImage`
object using one of `MlImage`'s
builder methods. See `MlImage`
documentation for more details.

Note that the width of the provided image cannot be less than 32 if `
FaceDetectorOptions.CONTOUR_MODE_ALL` is specified.

If the face detection model has not been downloaded yet when you are depending on
com.google.android.gms:play-services-mlkit-face-detection, the returned `Task` will
contain an `MlKitException`
with error code `MlKitException.UNAVAILABLE`.

If there is no face gets detected, the returned `Task` will
contain an empty `List`.

##### Returns

- a `Task` that asynchronously returns a `List` of detected `Face`s

#### public abstract Task\<[List](https://developer.android.com/reference/java/util/List.html)\<[Face](https://developers.google.com/android/reference/com/google/mlkit/vision/face/Face.md.txt)\>\>
**process** ([InputImage](https://developers.google.com/android/reference/com/google/mlkit/vision/common/InputImage.md.txt) image)

Detects human faces from the supplied image.

Create an `InputImage`
object using one of `InputImage`'s
factory methods. See `InputImage`
documentation for more details.

Note that the width of the provided image cannot be less than 32 if `
FaceDetectorOptions.CONTOUR_MODE_ALL` is specified.

If the face detection model has not been downloaded yet when you are depending on
com.google.android.gms:play-services-mlkit-face-detection, the returned `Task` will
contain an `MlKitException`
with error code `MlKitException.UNAVAILABLE`.

If there is no face gets detected, the returned `Task` will
contain an empty `List`.

##### Returns

- a `Task` that asynchronously returns a `List` of detected `Face`s