FaceMeshDetector
Stay organized with collections
Save and categorize content based on your preferences.
A FaceMeshDetection
client for finding FaceMesh
s in a
supplied image, which works best in selfie use case where face is within ~2 meters, or ~6.5
feet from the camera.
The FaceMeshDetection
provides two functionalities. When
FaceMeshDetectorOptions.BOUNDING_BOX_ONLY
is selected, it detects face bounding
box in selfie image with low latency(i.e. 12ms for a 640 * 360 image on Pixel 3). When
FaceMeshDetectorOptions.FACE_MESH
is selected, it detects at most 2 faces and for each detected face it provides extra 468 3D
points and its triangle information.
A FaceMeshDetector
is created via
FaceMeshDetection.getClient(FaceMeshDetectorOptions)
or FaceMeshDetection.getClient()
,
if you wish to use the default options. For example, the code below creates a FaceMeshDetector
client with default options.
FaceMeshDetector faceMeshDetector = FaceMeshDetection.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<FaceMesh>> task = faceMeshDetector.process(image);
task.addOnSuccessListener(...).addOnFailureListener(...);
Public Method Summary
abstract void |
close()
Closes the detector and releases its resources.
|
abstract Task<List<FaceMesh>>
|
|
abstract Task<List<FaceMesh>>
|
process(InputImage image)
Detects face mesh from the supplied image.
|
Inherited Method Summary
From interface java.io.Closeable
From interface java.lang.AutoCloseable
Public Methods
public abstract void close ()
Closes the detector and releases its resources.
public abstract Task<List<FaceMesh>>
process (MlImage
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.
If there is no face gets detected, the returned Task
will
contain an empty List
.
Detects face mesh from the supplied image.
Create an InputImage
object using one of InputImage
's
factory methods. See InputImage
documentation for more details.
If there is no face gets detected, the returned Task
will
contain an empty List
.
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\u003eFaceMeshDetector\u003c/code\u003e is a client for finding FaceMeshes in images, optimized for selfie use cases within ~2 meters.\u003c/p\u003e\n"],["\u003cp\u003eIt offers two functionalities: bounding box detection (fast) and detailed face mesh detection with 468 3D points.\u003c/p\u003e\n"],["\u003cp\u003eYou create a \u003ccode\u003eFaceMeshDetector\u003c/code\u003e using \u003ccode\u003eFaceMeshDetection.getClient()\u003c/code\u003e with optional configurations.\u003c/p\u003e\n"],["\u003cp\u003eTo detect faces, you process an \u003ccode\u003eInputImage\u003c/code\u003e or \u003ccode\u003eMlImage\u003c/code\u003e using the \u003ccode\u003eprocess()\u003c/code\u003e method, which returns a \u003ccode\u003eTask\u003c/code\u003e containing a list of \u003ccode\u003eFaceMesh\u003c/code\u003e objects.\u003c/p\u003e\n"],["\u003cp\u003eWhen no faces are detected, the \u003ccode\u003eTask\u003c/code\u003e will contain an empty list.\u003c/p\u003e\n"]]],[],null,["# FaceMeshDetector\n\npublic interface **FaceMeshDetector** extends Detector\\\u003c[List](//developer.android.com/reference/java/util/List.html)\\\u003c[FaceMesh](/android/reference/com/google/mlkit/vision/facemesh/FaceMesh)\\\u003e\\\u003e \nA [FaceMeshDetection](/android/reference/com/google/mlkit/vision/facemesh/FaceMeshDetection)\nclient for finding [FaceMesh](/android/reference/com/google/mlkit/vision/facemesh/FaceMesh)s in a\nsupplied image, which works best in selfie use case where face is within \\~2 meters, or \\~6.5\nfeet from the camera.\n\nThe [FaceMeshDetection](/android/reference/com/google/mlkit/vision/facemesh/FaceMeshDetection)\nprovides two functionalities. When [FaceMeshDetectorOptions.BOUNDING_BOX_ONLY](/android/reference/com/google/mlkit/vision/facemesh/FaceMeshDetectorOptions#BOUNDING_BOX_ONLY) is selected, it detects face bounding\nbox in selfie image with low latency(i.e. 12ms for a 640 \\* 360 image on Pixel 3). When\n[FaceMeshDetectorOptions.FACE_MESH](/android/reference/com/google/mlkit/vision/facemesh/FaceMeshDetectorOptions#FACE_MESH)\nis selected, it detects at most 2 faces and for each detected face it provides extra 468 3D\npoints and its triangle information.\n\nA [FaceMeshDetector](/android/reference/com/google/mlkit/vision/facemesh/FaceMeshDetector)\nis created via [FaceMeshDetection.getClient(FaceMeshDetectorOptions)](/android/reference/com/google/mlkit/vision/facemesh/FaceMeshDetection#getClient(com.google.mlkit.vision.facemesh.FaceMeshDetectorOptions)) or [FaceMeshDetection.getClient()](/android/reference/com/google/mlkit/vision/facemesh/FaceMeshDetection#getClient()),\nif you wish to use the default options. For example, the code below creates a [FaceMeshDetector](/android/reference/com/google/mlkit/vision/facemesh/FaceMeshDetector)\nclient with default options. \n\n FaceMeshDetector faceMeshDetector = FaceMeshDetection.getClient();\n \nTo perform face detection in an image, you first need to create an instance of `\n`[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\u003cFaceMesh\u003e\u003e task = faceMeshDetector.process(image);\n task.addOnSuccessListener(...).addOnFailureListener(...);\n \n### Public Method Summary\n\n|------------------------------------------------------------------------------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| abstract void | [close](/android/reference/com/google/mlkit/vision/facemesh/FaceMeshDetector#close())() Closes the detector and releases its resources. |\n| abstract Task\\\u003c[List](//developer.android.com/reference/java/util/List.html)\\\u003c[FaceMesh](/android/reference/com/google/mlkit/vision/facemesh/FaceMesh)\\\u003e\\\u003e | [process](/android/reference/com/google/mlkit/vision/facemesh/FaceMeshDetector#process(com.google.android.odml.image.MlImage))([MlImage](/android/reference/com/google/android/odml/image/MlImage) image) Detects human faces from the supplied image. |\n| abstract Task\\\u003c[List](//developer.android.com/reference/java/util/List.html)\\\u003c[FaceMesh](/android/reference/com/google/mlkit/vision/facemesh/FaceMesh)\\\u003e\\\u003e | [process](/android/reference/com/google/mlkit/vision/facemesh/FaceMeshDetector#process(com.google.mlkit.vision.common.InputImage))(InputImage image) Detects face mesh from the supplied image. |\n\n### Inherited Method Summary\n\nFrom interface java.io.Closeable \n\n|---------------|---------|\n| abstract void | close() |\n\nFrom interface java.lang.AutoCloseable \n\n|---------------|---------|\n| abstract void | close() |\n\nPublic Methods\n--------------\n\n#### public abstract void **close** ()\n\nCloses the detector and releases its resources. \n\n#### public abstract Task\\\u003c[List](//developer.android.com/reference/java/util/List.html)\\\u003c[FaceMesh](/android/reference/com/google/mlkit/vision/facemesh/FaceMesh)\\\u003e\\\u003e\n**process** ([MlImage](/android/reference/com/google/android/odml/image/MlImage) image)\n\nDetects human faces from the supplied image.\n\nThis is an experimental API in beta version.\n\nCreate an [MlImage](/android/reference/com/google/android/odml/image/MlImage)\nobject using one of [MlImage](/android/reference/com/google/android/odml/image/MlImage)'s\nbuilder methods. See [MlImage](/android/reference/com/google/android/odml/image/MlImage)\ndocumentation for more details.\n\nIf there is no face gets detected, the returned [Task](/android/reference/com/google/android/gms/tasks/Task) will\ncontain an empty [List](//developer.android.com/reference/java/util/List.html). \n\n##### Returns\n\n- a [Task](/android/reference/com/google/android/gms/tasks/Task) that asynchronously returns a [List](//developer.android.com/reference/java/util/List.html) of detected [FaceMesh](/android/reference/com/google/mlkit/vision/facemesh/FaceMesh)s \n\n#### public abstract Task\\\u003c[List](//developer.android.com/reference/java/util/List.html)\\\u003c[FaceMesh](/android/reference/com/google/mlkit/vision/facemesh/FaceMesh)\\\u003e\\\u003e\n**process** (InputImage image)\n\nDetects face mesh from the supplied image.\n\nCreate an [InputImage](/android/reference/com/google/mlkit/vision/common/InputImage)\nobject using one of [InputImage](/android/reference/com/google/mlkit/vision/common/InputImage)'s\nfactory methods. See [InputImage](/android/reference/com/google/mlkit/vision/common/InputImage)\ndocumentation for more details.\n\nIf there is no face gets detected, the returned [Task](/android/reference/com/google/android/gms/tasks/Task) will\ncontain an empty [List](//developer.android.com/reference/java/util/List.html). \n\n##### Returns\n\n- a [Task](/android/reference/com/google/android/gms/tasks/Task) that asynchronously returns a [List](//developer.android.com/reference/java/util/List.html) of detected [FaceMesh](/android/reference/com/google/mlkit/vision/facemesh/FaceMesh)s"]]