FaceDetection
Stay organized with collections
Save and categorize content based on your preferences.
Entry point to get a FaceDetector
for finding Face
s in a supplied
image.
A FaceDetector
is created via
getClient(FaceDetectorOptions)
or getClient()
if you wish to use the default options. For example, the code below creates a FaceDetector
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(...);
Inherited Method Summary
From class java.lang.Object
Object
|
clone()
|
boolean |
|
void |
finalize()
|
final Class<?>
|
getClass()
|
int |
hashCode()
|
final void |
notify()
|
final void |
notifyAll()
|
String
|
toString()
|
final void |
wait(long arg0, int arg1)
|
final void |
wait(long arg0)
|
final void |
wait()
|
Public Methods
Gets a new instance of FaceDetector
that detects faces in a supplied image.
To release the resources associated with a FaceDetector, you need to ensure that
FaceDetector.close()
is called on the resulting FaceDetector
object once it will no longer be used.
Parameters
options |
the options for the face detector |
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2024-10-31 UTC.
[null,null,["Last updated 2024-10-31 UTC."],[[["\u003cp\u003e\u003ccode\u003eFaceDetection\u003c/code\u003e is the entry point for using ML Kit's face detection capabilities to find faces within images.\u003c/p\u003e\n"],["\u003cp\u003eYou create a \u003ccode\u003eFaceDetector\u003c/code\u003e instance using \u003ccode\u003eFaceDetection.getClient()\u003c/code\u003e with optional custom options or default settings.\u003c/p\u003e\n"],["\u003cp\u003eFace detection is performed by processing an \u003ccode\u003eInputImage\u003c/code\u003e created from a source like a Bitmap using the \u003ccode\u003eFaceDetector\u003c/code\u003e.\u003c/p\u003e\n"],["\u003cp\u003eTo obtain specific facial features, use the methods in the \u003ccode\u003eFace\u003c/code\u003e object.\u003c/p\u003e\n"],["\u003cp\u003eRemember to release the \u003ccode\u003eFaceDetector\u003c/code\u003e resources when done by calling \u003ccode\u003eFaceDetector.close()\u003c/code\u003e.\u003c/p\u003e\n"]]],[],null,["# FaceDetection\n\npublic class **FaceDetection** extends [Object](//developer.android.com/reference/java/lang/Object.html) \nEntry point to get a [FaceDetector](/android/reference/com/google/mlkit/vision/face/FaceDetector)\nfor finding [Face](/android/reference/com/google/mlkit/vision/face/Face)s in a supplied\nimage.\n\nA [FaceDetector](/android/reference/com/google/mlkit/vision/face/FaceDetector)\nis created via [getClient(FaceDetectorOptions)](/android/reference/com/google/mlkit/vision/face/FaceDetection#getClient(com.google.mlkit.vision.face.FaceDetectorOptions)) or [getClient()](/android/reference/com/google/mlkit/vision/face/FaceDetection#getClient())\nif you wish to use the default options. For example, the code below creates a [FaceDetector](/android/reference/com/google/mlkit/vision/face/FaceDetector)\nwith default options. \n\n FaceDetector faceDetector = FaceDetection.getClient(); \n\nTo perform face detection in an image, you first need to create an instance of [InputImage](/android/reference/com/google/mlkit/vision/common/InputImage) from a [Bitmap](//developer.android.com/reference/android/graphics/Bitmap.html), [ByteBuffer](//developer.android.com/reference/java/nio/ByteBuffer.html), [Image](//developer.android.com/reference/android/media/Image.html) etc. See [InputImage](/android/reference/com/google/mlkit/vision/common/InputImage) documentation for more details. For example, the code below creates an [InputImage](/android/reference/com/google/mlkit/vision/common/InputImage) from a [Bitmap](//developer.android.com/reference/android/graphics/Bitmap.html). \n\n InputImage image = InputImage.fromBitmap(bitmap, rotationDegrees); \n\nThen the code below can detect faces in the supplied [InputImage](/android/reference/com/google/mlkit/vision/common/InputImage). \n\n Task\u003cList\u003cFace\u003e\u003e task = faceDetector.process(image);\n task.addOnSuccessListener(...).addOnFailureListener(...); \n\n### Public Method Summary\n\n|-------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| static [FaceDetector](/android/reference/com/google/mlkit/vision/face/FaceDetector) | [getClient](/android/reference/com/google/mlkit/vision/face/FaceDetection#getClient(com.google.mlkit.vision.face.FaceDetectorOptions))([FaceDetectorOptions](/android/reference/com/google/mlkit/vision/face/FaceDetectorOptions) options) Gets a new instance of [FaceDetector](/android/reference/com/google/mlkit/vision/face/FaceDetector) that detects faces in a supplied image. |\n| static [FaceDetector](/android/reference/com/google/mlkit/vision/face/FaceDetector) | [getClient](/android/reference/com/google/mlkit/vision/face/FaceDetection#getClient())() Gets an instance of [FaceDetector](/android/reference/com/google/mlkit/vision/face/FaceDetector) that detects faces in a supplied image with a default [FaceDetectorOptions](/android/reference/com/google/mlkit/vision/face/FaceDetectorOptions). |\n\n### Inherited Method Summary\n\nFrom class java.lang.Object \n\n|----------------------------------------------------------------------------|--------------------------------------------------------------------------------|\n| [Object](//developer.android.com/reference/java/lang/Object.html) | clone() |\n| boolean | equals([Object](//developer.android.com/reference/java/lang/Object.html) arg0) |\n| void | finalize() |\n| final [Class](//developer.android.com/reference/java/lang/Class.html)\\\u003c?\\\u003e | getClass() |\n| int | hashCode() |\n| final void | notify() |\n| final void | notifyAll() |\n| [String](//developer.android.com/reference/java/lang/String.html) | toString() |\n| final void | wait(long arg0, int arg1) |\n| final void | wait(long arg0) |\n| final void | wait() |\n\nPublic Methods\n--------------\n\n#### public static [FaceDetector](/android/reference/com/google/mlkit/vision/face/FaceDetector)\n**getClient** ([FaceDetectorOptions](/android/reference/com/google/mlkit/vision/face/FaceDetectorOptions) options)\n\nGets a new instance of [FaceDetector](/android/reference/com/google/mlkit/vision/face/FaceDetector)\nthat detects faces in a supplied image.\n\nTo release the resources associated with a FaceDetector, you need to ensure that\n[FaceDetector.close()](/android/reference/com/google/mlkit/vision/face/FaceDetector#close())\nis called on the resulting [FaceDetector](/android/reference/com/google/mlkit/vision/face/FaceDetector)\nobject once it will no longer be used. \n\n##### Parameters\n\n| options | the options for the face detector |\n|---------|-----------------------------------|\n\n#### public static [FaceDetector](/android/reference/com/google/mlkit/vision/face/FaceDetector)\n**getClient** ()\n\nGets an instance of [FaceDetector](/android/reference/com/google/mlkit/vision/face/FaceDetector)\nthat detects faces in a supplied image with a default [FaceDetectorOptions](/android/reference/com/google/mlkit/vision/face/FaceDetectorOptions)."]]