Stay organized with collections
Save and categorize content based on your preferences.
Face
open class Face
Information about a face identified through camera face detection.
When face detection is used with a camera, the FaceDetectionListener
returns a list of face objects for use in focusing and metering.
Summary
Public constructors |
Create an empty face.
|
Properties |
Int |
An unique id per face while the face is visible to the tracker.
|
Point! |
The coordinates of the center of the left eye.
|
Point! |
The coordinates of the center of the mouth.
|
Rect! |
Bounds of the face.
|
Point! |
The coordinates of the center of the right eye.
|
Int |
The confidence level for the detection of the face.
|
Public constructors
Face
Face()
Create an empty face.
Properties
id
var id: Int
Deprecated: Deprecated in Java.
An unique id per face while the face is visible to the tracker. If the face leaves the field-of-view and comes back, it will get a new id. This is an optional field, may not be supported on all devices. If not supported, id will always be set to -1. The optional fields are supported as a set. Either they are all valid, or none of them are.
leftEye
var leftEye: Point!
Deprecated: Deprecated in Java.
The coordinates of the center of the left eye. The coordinates are in the same space as the ones for rect
. This is an optional field, may not be supported on all devices. If not supported, the value will always be set to null. The optional fields are supported as a set. Either they are all valid, or none of them are.
mouth
var mouth: Point!
Deprecated: Deprecated in Java.
The coordinates of the center of the mouth. The coordinates are in the same space as the ones for rect
. This is an optional field, may not be supported on all devices. If not supported, the value will always be set to null. The optional fields are supported as a set. Either they are all valid, or none of them are.
rect
var rect: Rect!
Deprecated: Deprecated in Java.
Bounds of the face. (-1000, -1000) represents the top-left of the camera field of view, and (1000, 1000) represents the bottom-right of the field of view. For example, suppose the size of the viewfinder UI is 800x480. The rect passed from the driver is (-1000, -1000, 0, 0). The corresponding viewfinder rect should be (0, 0, 400, 240). It is guaranteed left < right and top < bottom. The coordinates can be smaller than -1000 or bigger than 1000. But at least one vertex will be within (-1000, -1000) and (1000, 1000).
The direction is relative to the sensor orientation, that is, what the sensor sees. The direction is not affected by the rotation or mirroring of setDisplayOrientation(int)
. The face bounding rectangle does not provide any information about face orientation.
Here is the matrix to convert driver coordinates to View coordinates in pixels.
Matrix matrix = new Matrix();
CameraInfo info = CameraHolder.instance().getCameraInfo()[cameraId];
// Need mirror for front camera.
boolean mirror = (info.facing == CameraInfo.CAMERA_FACING_FRONT);
matrix.setScale(mirror ? -1 : 1, 1);
// This is the value for android.hardware.Camera.setDisplayOrientation.
matrix.postRotate(displayOrientation);
// Camera driver coordinates range from (-1000, -1000) to (1000, 1000).
// UI coordinates range from (0, 0) to (width, height).
matrix.postScale(view.getWidth() / 2000f, view.getHeight() / 2000f);
matrix.postTranslate(view.getWidth() / 2f, view.getHeight() / 2f);
rightEye
var rightEye: Point!
Deprecated: Deprecated in Java.
The coordinates of the center of the right eye. The coordinates are in the same space as the ones for rect
.This is an optional field, may not be supported on all devices. If not supported, the value will always be set to null. The optional fields are supported as a set. Either they are all valid, or none of them are.
score
var score: Int
Deprecated: Deprecated in Java.
The confidence level for the detection of the face. The range is 1 to 100. 100 is the highest confidence.
Depending on the device, even very low-confidence faces may be listed, so applications should filter out faces with low confidence, depending on the use case. For a typical point-and-shoot camera application that wishes to display rectangles around detected faces, filtering out faces with confidence less than 50 is recommended.
Content and code samples on this page are subject to the licenses described in the Content License. Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.
Last updated 2025-02-10 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-02-10 UTC."],[],[],null,["# Camera.Face\n\nAdded in [API level 14](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels) \nDeprecated in [API level 21](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)\n\nFace\n====\n\n*** ** * ** ***\n\nKotlin \\|[Java](/reference/android/hardware/Camera.Face \"View this page in Java\") \n\n```\nopen class Face\n```\n\n|---|-----------------------------------|\n| [kotlin.Any](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html) ||\n| ↳ | [android.hardware.Camera.Face](#) |\n\n*** ** * ** ***\n\n| **This class was deprecated in API level 21.**\n|\n| We recommend using the new [android.hardware.camera2](/reference/kotlin/android/hardware/camera2/package-summary) API for new applications.\n\nInformation about a face identified through camera face detection.\n\nWhen face detection is used with a camera, the [FaceDetectionListener](/reference/kotlin/android/hardware/Camera.FaceDetectionListener) returns a list of face objects for use in focusing and metering.\n\nSummary\n-------\n\n| Public constructors ||\n|-------------------------------------------|---|\n| [Face](#Face())`()` Create an empty face. |\n\n| Properties ||\n|----------------------------------------------------------------------------|----------------------------------------------------------------------------------------------|\n| [Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html) | [id](#id:kotlin.Int) An unique id per face while the face is visible to the tracker. |\n| [Point](../graphics/Point.html#)! | [leftEye](#leftEye:android.graphics.Point) The coordinates of the center of the left eye. |\n| [Point](../graphics/Point.html#)! | [mouth](#mouth:android.graphics.Point) The coordinates of the center of the mouth. |\n| [Rect](../graphics/Rect.html#)! | [rect](#rect:android.graphics.Rect) Bounds of the face. |\n| [Point](../graphics/Point.html#)! | [rightEye](#rightEye:android.graphics.Point) The coordinates of the center of the right eye. |\n| [Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html) | [score](#score:kotlin.Int) The confidence level for the detection of the face. |\n\nPublic constructors\n-------------------\n\n### Face\n\nAdded in [API level 14](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels) \n\n```\nFace()\n```\n\nCreate an empty face.\n\nProperties\n----------\n\n### id\n\nAdded in [API level 14](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels) \n\n```\nvar id: Int\n```\n\n**Deprecated:** *Deprecated in Java.*\n\nAn unique id per face while the face is visible to the tracker. If the face leaves the field-of-view and comes back, it will get a new id. This is an optional field, may not be supported on all devices. If not supported, id will always be set to -1. The optional fields are supported as a set. Either they are all valid, or none of them are. \n\n### leftEye\n\nAdded in [API level 14](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels) \n\n```\nvar leftEye: Point!\n```\n\n**Deprecated:** *Deprecated in Java.*\n\nThe coordinates of the center of the left eye. The coordinates are in the same space as the ones for [rect](#rect:android.graphics.Rect). This is an optional field, may not be supported on all devices. If not supported, the value will always be set to null. The optional fields are supported as a set. Either they are all valid, or none of them are. \n\n### mouth\n\nAdded in [API level 14](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels) \n\n```\nvar mouth: Point!\n```\n\n**Deprecated:** *Deprecated in Java.*\n\nThe coordinates of the center of the mouth. The coordinates are in the same space as the ones for [rect](#rect:android.graphics.Rect). This is an optional field, may not be supported on all devices. If not supported, the value will always be set to null. The optional fields are supported as a set. Either they are all valid, or none of them are. \n\n### rect\n\nAdded in [API level 14](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels) \n\n```\nvar rect: Rect!\n```\n\n**Deprecated:** *Deprecated in Java.*\n\nBounds of the face. (-1000, -1000) represents the top-left of the camera field of view, and (1000, 1000) represents the bottom-right of the field of view. For example, suppose the size of the viewfinder UI is 800x480. The rect passed from the driver is (-1000, -1000, 0, 0). The corresponding viewfinder rect should be (0, 0, 400, 240). It is guaranteed left \\\u003c right and top \\\u003c bottom. The coordinates can be smaller than -1000 or bigger than 1000. But at least one vertex will be within (-1000, -1000) and (1000, 1000).\n\nThe direction is relative to the sensor orientation, that is, what the sensor sees. The direction is not affected by the rotation or mirroring of [setDisplayOrientation(int)](/reference/kotlin/android/hardware/Camera#setDisplayOrientation(kotlin.Int)). The face bounding rectangle does not provide any information about face orientation.\n\nHere is the matrix to convert driver coordinates to View coordinates in pixels. \n\n```kotlin\nMatrix matrix = new Matrix();\n CameraInfo info = CameraHolder.instance().getCameraInfo()[cameraId];\n // Need mirror for front camera.\n boolean mirror = (info.facing == CameraInfo.CAMERA_FACING_FRONT);\n matrix.setScale(mirror ? -1 : 1, 1);\n // This is the value for android.hardware.Camera.setDisplayOrientation.\n matrix.postRotate(displayOrientation);\n // Camera driver coordinates range from (-1000, -1000) to (1000, 1000).\n // UI coordinates range from (0, 0) to (width, height).\n matrix.postScale(view.getWidth() / 2000f, view.getHeight() / 2000f);\n matrix.postTranslate(view.getWidth() / 2f, view.getHeight() / 2f);\n \n``` \n**See Also**\n\n- [#startFaceDetection()](/reference/kotlin/android/hardware/Camera#startFaceDetection()) \n\n### rightEye\n\nAdded in [API level 14](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels) \n\n```\nvar rightEye: Point!\n```\n\n**Deprecated:** *Deprecated in Java.*\n\nThe coordinates of the center of the right eye. The coordinates are in the same space as the ones for [rect](#rect:android.graphics.Rect).This is an optional field, may not be supported on all devices. If not supported, the value will always be set to null. The optional fields are supported as a set. Either they are all valid, or none of them are. \n\n### score\n\nAdded in [API level 14](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels) \n\n```\nvar score: Int\n```\n\n**Deprecated:** *Deprecated in Java.*\n\nThe confidence level for the detection of the face. The range is 1 to 100. 100 is the highest confidence.\n\nDepending on the device, even very low-confidence faces may be listed, so applications should filter out faces with low confidence, depending on the use case. For a typical point-and-shoot camera application that wishes to display rectangles around detected faces, filtering out faces with confidence less than 50 is recommended. \n**See Also**\n\n- [#startFaceDetection()](/reference/kotlin/android/hardware/Camera#startFaceDetection())"]]