臉部偵測概念
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
臉部偵測功能會在視覺媒體 (例如數位圖片或影片) 中尋找人臉。當偵測到臉孔有相關聯的位置、大小和方向,可以搜尋眼睛和鼻子等地標。
以下是與 ML Kit 臉部偵測功能相關的一些字詞:
臉部追蹤可將臉部偵測功能擴展到影片序列,從影格到每個影格,都能追蹤片中長度任意長度的臉孔。這表示在連續視訊影格中偵測到的臉孔,可識別為同一個人。請注意,這不是「臉部辨識」的形式。臉部追蹤只會根據影片序列中臉孔的位置和動作進行推論。
「地標」是指表面中的搜尋點。左眼、右眼和鼻子都是地標的例子。ML Kit 可讓您在偵測到的臉孔中尋找地標。
輪廓是一組隨臉部地圖項目形狀的點。ML Kit 提供找出臉部的輪廓。
「分類」可判斷是否存在特定的臉部特徵。舉例來說,您可將臉孔區分為面部處於開啟或關閉、笑臉、笑臉等。
正面
以下字詞說明臉孔與相機相關的角度:
- Euler X:帶有正 X 角的臉孔朝上。
- Euler Y:帶有正數 Y 角的臉部朝向相機右側,如為負數,請向左尋找。
- Euler Z:帶有正 Z 角的臉孔,相對於相機,其逆時針旋轉。
當 LANDMARK_MODE_NONE
、CONTOUR_MODE_ALL
、CLASSIFICATION_MODE_NONE
和 PERFORMANCE_MODE_FAST
一起設定時,ML Kit 不會回報偵測到的臉部的 Euler X、Euler Y 或 Euler Z 角度。
地標
地標是指臉孔中的搜尋點。左眼、右眼和鼻子都是地標的範例。
ML Kit 無須尋找地標即可偵測臉孔。地標偵測功能為選用步驟,預設為停用。
下表摘要列出若特定臉孔的 Y 軸角度,可以偵測到的所有地標:
歐拉 Y 角 |
可偵測的地標 |
< -36 度 |
左眼, 左眼, 左耳, 鼻基, 左腳 |
-36 度到 -12 度 |
左嘴, 鼻子, 下口, 下眼, 右眼, 左眼, 左溪, 左耳塞套 |
-12 度到 12 度 |
右眼, 左眼, 鼻子, 左溪, 右溪, 左嘴, 右嘴, 下嘴 |
12 度到 36 度 |
右嘴, 鼻子, 下口, 左眼, 左眼, 右眼, 右溪, 右耳塞套 |
> 36 度 |
右眼, 右眼, 右耳, 鼻基, 右臉頰 |
每個偵測到的地標在圖片中都有相關聯的位置。
輪廓
輪廓是一組點,代表臉部特徵的形狀。下圖說明這些點如何對應到臉孔。按一下圖片即可放大:
每個 ML Kit 偵測到的特徵輪廓會以固定數量的點表示:
橢圓形 |
36 分 |
上唇 (頂部) |
11 分 |
左眉 (上方) |
5 分 |
上唇 (底部) |
9 分 |
左眉 (底部) |
5 分 |
下唇 (頂部) |
9 分 |
右眉 (上方) |
5 分 |
下唇 (底部) |
9 分 |
右眉 (底部) |
5 分 |
鼻橋 |
2 分 |
左眼 |
16 分 |
鼻子底部 |
3 分 |
右眼 |
16 分 |
左溪 (中間) |
1 分 |
右溪 (中間) |
1 分 |
一次取得所有臉孔的輪廓時,您會收到包含 133 個點的陣列,該陣列會對應至不同的輪廓,如下所示:
特徵輪廓的索引 |
0-35 |
橢圓形 |
36-40 |
左眉 (上方) |
41-45 |
左眉 (底部) |
46-50 |
右眉 (上方) |
51-55 |
右眉 (底部) |
56-71 |
左眼 |
72-87 |
右眼 |
88-96 |
上唇 (底部) |
97-105 |
下唇 (頂部) |
106-116 |
上唇 (頂部) |
117-125 |
下唇 (底部) |
126、127 |
鼻橋 |
128-130 |
下鼻子 (請注意,中心點位於索引 128) |
131 |
左溪 (中間) |
132 |
右溪 (中間) |
分類
分類可決定特定臉部特徵是否存在。
ML Kit 目前支援兩種分類:「眼睛開放」和「笑臉」。
分類是確定值。代表臉部特徵存在的信賴水準。舉例來說,如果值為 0.7 以上的圖片分類,表示某人可能有在微笑。
這兩種分類都必須仰賴地標偵測。
另請注意,「眼睛開放」和「面露笑」分類僅適用於正面臉孔,也就是較小的歐拉 Y 角 (介於 -18 到 18 度之間) 的臉孔。
臉部最小尺寸
最小臉孔大小是所需的臉孔大小,以頭部的寬度與圖片寬度的比例表示。舉例來說,值為 0.1 表示要搜尋的最小臉孔約佔搜尋圖片寬度的 10%。
臉孔最小尺寸代表效能與準確率的取捨:設定較小的臉孔下限可讓偵測工具找到較小的臉孔,但偵測所需的時間較長;設定較大的臉孔可能會排除較小的臉孔,但執行速度更快。
臉孔大小下限並非硬性限制;偵測工具可能會找到比指定範圍稍小的臉孔。
後續步驟
在 iOS 或 Android 應用程式中使用臉部偵測功能:
除非另有註明,否則本頁面中的內容是採用創用 CC 姓名標示 4.0 授權,程式碼範例則為阿帕契 2.0 授權。詳情請參閱《Google Developers 網站政策》。Java 是 Oracle 和/或其關聯企業的註冊商標。
上次更新時間:2025-08-29 (世界標準時間)。
[null,null,["上次更新時間:2025-08-29 (世界標準時間)。"],[[["\u003cp\u003eML Kit's face detection feature locates and analyzes human faces in images and videos, identifying position, size, orientation, and facial landmarks like eyes and nose.\u003c/p\u003e\n"],["\u003cp\u003eFace tracking in ML Kit follows faces across video frames, enabling the identification of the same person without using facial recognition.\u003c/p\u003e\n"],["\u003cp\u003eOptional features include landmark detection (identifying points like eyes, nose, mouth), contour detection (outlining facial features), and classification (detecting smiles or open eyes).\u003c/p\u003e\n"],["\u003cp\u003ePerformance can be adjusted by setting the minimum face size, balancing speed and accuracy of detection.\u003c/p\u003e\n"]]],[],null,["Face detection locates human faces in visual media such as digital images or\nvideo. When a face is detected it has an associated position, size, and\norientation; and it can be searched for landmarks such as the eyes and nose.\n\nHere are some of the terms that we use regarding the face detection feature\nof ML Kit:\n\n- **Face tracking** extends face detection to video sequences. Any face that\n appears in a video for any length of time can be tracked from frame to frame.\n This means a face detected in consecutive video frames can be identified as\n being the same person. Note that this isn't a form of *face recognition*; face\n tracking only makes inferences based on the position and motion of the faces in\n a video sequence.\n\n- A **landmark** is a point of interest within a face. The left eye, right eye,\n and base of the nose are all examples of landmarks. ML Kit provides the\n ability to find landmarks on a detected face.\n\n- A **contour** is a set of points that follow the shape of a facial feature.\n ML Kit provides the ability to find the contours of a face.\n\n- **Classification** determines whether a certain facial\n characteristic is present. For example, a face can be classified by\n whether its eyes are open or closed, or if the face is smiling or not.\n\nFace orientation\n\nThe following terms describe the angle a face is oriented with respect to the\ncamera:\n\n- **Euler X**: A face with a positive Euler X angle is facing upward.\n- **Euler Y**: A face with a positive Euler Y angle is looking to the right of the camera, or looking to the left if negative.\n- **Euler Z**: A face with a positive Euler Z angle is rotated counter-clockwise relative to the camera.\n\nML Kit doesn't report the Euler X, Euler Y or Euler Z angle of a detected face when\n`LANDMARK_MODE_NONE`, `CONTOUR_MODE_ALL`, `CLASSIFICATION_MODE_NONE` and\n`PERFORMANCE_MODE_FAST`are set together.\n\nLandmarks\n\nA landmark is a point of interest within a face. The left eye, right eye, and\nnose base are all examples of landmarks.\n\nML Kit detects faces without looking for landmarks.\nLandmark detection is an optional step that is disabled by default.\n\nThe following table summarizes all of the landmarks that can be detected given\nthe Euler Y angle of an associated face:\n\n| Euler Y angle | Detectable landmarks |\n|----------------------------|------------------------------------------------------------------------------------------------|\n| \\\u003c -36 degrees | left eye, left mouth, left ear, nose base, left cheek |\n| -36 degrees to -12 degrees | left mouth, nose base, bottom mouth, right eye, left eye, left cheek, left ear tip |\n| -12 degrees to 12 degrees | right eye, left eye, nose base, left cheek, right cheek, left mouth, right mouth, bottom mouth |\n| 12 degrees to 36 degrees | right mouth, nose base, bottom mouth, left eye, right eye, right cheek, right ear tip |\n| \\\u003e 36 degrees | right eye, right mouth, right ear, nose base, right cheek |\n\nEach detected landmark includes its associated position in the image.\n\nContours\n\nA contour is a set of points that represent the shape of a facial feature. The\nfollowing image illustrates how these points map to a face. Click the image to\nenlarge it:\n\n[](/static/ml-kit/vision/face-detection/images/face_contours.svg)\n\nEach feature contour that ML Kit detects is represented by a fixed number of\npoints:\n\n| Face oval | 36 points | Upper lip (top) | 11 points |\n| Left eyebrow (top) | 5 points | Upper lip (bottom) | 9 points |\n| Left eyebrow (bottom) | 5 points | Lower lip (top) | 9 points |\n| Right eyebrow (top) | 5 points | Lower lip (bottom) | 9 points |\n| Right eyebrow (bottom) | 5 points | Nose bridge | 2 points |\n| Left eye | 16 points | Nose bottom | 3 points |\n| Right eye | 16 points |\n| Left cheek (center) | 1 point |\n| Right cheek (center) | 1 points |\n|------------------------|-----------|--------------------|-----------|\n\nWhen you get all of a face's contours at once, you get an array of 133 points,\nwhich map to feature contours as shown below:\n\n| Indexes of feature contours ||\n|----------|----------------------------------------------------------|\n| 0-35 | Face oval |\n| 36-40 | Left eyebrow (top) |\n| 41-45 | Left eyebrow (bottom) |\n| 46-50 | Right eyebrow (top) |\n| 51-55 | Right eyebrow (bottom) |\n| 56-71 | Left eye |\n| 72-87 | Right eye |\n| 88-96 | Upper lip (bottom) |\n| 97-105 | Lower lip (top) |\n| 106-116 | Upper lip (top) |\n| 117-125 | Lower lip (bottom) |\n| 126, 127 | Nose bridge |\n| 128-130 | Nose bottom (note that the center point is at index 128) |\n| 131 | Left cheek (center) |\n| 132 | Right cheek (center) |\n\nClassification\n\nClassification determines whether a certain facial characteristic is present.\nML Kit currently supports two classifications: **eyes open** and **smiling**.\n\nClassification is a certainty value. It indicates the confidence\nthat a facial characteristic is present. For example, a value of 0.7 or more\nfor the smiling classification indicates that it's likely that a person is\nsmiling.\n\nBoth of these classifications rely upon landmark detection.\n\nAlso note that the classifications \"eyes open\" and \"smiling\" only work for\nfrontal faces, i.e., faces with a small Euler Y angle (between -18 and 18\ndegrees).\n\nMinimum Face Size\n\nThe minimum face size is the desired face size, expressed as the ratio of the width of\nthe head to the width of the image. For example, the value of 0.1 means that\nthe smallest face to search for is roughly 10% of the width of the image being\nsearched.\n\nThe minimum face size is a performance vs. accuracy trade-off: setting the\nminimum size smaller lets the detector find smaller faces but detection\nwill take longer; setting it larger might exclude smaller faces but\nwill run faster.\n\nThe minimum face size is not a hard limit; the detector may find faces slightly\nsmaller than specified.\n\nNext Steps\n\nUse face detection in your iOS or Android app:\n\n- [iOS](/ml-kit/vision/face-detection/ios)\n- [Android](/ml-kit/vision/face-detection/android)"]]