臉部偵測
透過集合功能整理內容
你可以依據偏好儲存及分類內容。

透過 ML Kit 的臉部偵測 API,您可以偵測圖片中的臉孔、識別重要的臉部特徵,並取得偵測到的臉孔輪廓。請注意,API 會偵測臉孔,但無法「辨識人物」。
透過臉部偵測功能,您可以取得執行工作所需的資訊,例如裝飾自拍照和肖像,或是利用使用者的相片產生虛擬化身。由於 ML Kit 可以即時執行臉部偵測,因此您可以在諸如視訊通訊或遊戲等能回應玩家表情的應用程式中使用它。
iOS
Android
主要功能
- 辨識及尋找臉部特徵
取得每個偵測到臉孔的眼睛、耳朵、臉頰、鼻子和嘴巴座標。
- 取得臉部特徵輪廓
偵測偵測到的臉孔及其眼睛、眉毛、唇膏和鼻子。
- 辨識臉部表情
判斷是否有人微笑或閉眼。
- 跨影片影格追蹤臉孔
取得每個偵測到的不重複臉孔 ID。
ID 會在每次叫用時保持一致,因此您可以對影片串流中的特定使用者執行圖片操控。
- 即時處理影片影格
臉部偵測是在裝置中執行,其速度夠快,可用於即時應用程式,例如影片操弄。
搜尋結果範例
範例 1

針對每個偵測到的臉孔:
第 1 張臉孔 (共 3 張) |
定界多邊形 |
(884.880004882812、149.546676635742)、(1030.77197265625, 149.546676635742)、(1030.77197265628620862086208) |
旋轉角度 |
Y:-14.054030418395996、Z:-55.007488250732422 |
追蹤 ID |
2 |
特色地標 |
左眼 |
(945.869323730469、211.867126464844) |
右眼 |
(971.579467773438、247.257247924805) |
嘴巴底部 |
(907.756591796875、259.714477539062) |
...等等
|
特徵機率 |
微笑 |
0.88979166746139526 |
左眼張開 |
0.98635888937860727 |
右眼已開啟 |
0.99258323386311531 |
|
範例 2 (臉部輪廓偵測)
啟用臉部輪廓偵測功能後,系統會列出偵測到的各項臉部特徵。這些點代表地圖項目的形狀。下圖說明這些點如何對應到臉孔。按一下圖片即可放大:
臉部特徵輪廓 |
鼻橋 |
(505.149811、221.201797)、(506.987122、313.285919)
|
左眼 |
(404.642029、232.854431)、(408.52.854431)、(408.52.854431)、(408.527283, 231.366623)、(413.565796、229.427856) |
上唇部頂端 |
(421.662048、354.520813)、(428.103882, 349.694061)、(440.847595、348.048737)、(456.549988, 354.520813)、(7.30,495,451,895,451 |
(等等) |
|
除非另有註明,否則本頁面中的內容是採用創用 CC 姓名標示 4.0 授權,程式碼範例則為阿帕契 2.0 授權。詳情請參閱《Google Developers 網站政策》。Java 是 Oracle 和/或其關聯企業的註冊商標。
上次更新時間:2025-08-29 (世界標準時間)。
[null,null,["上次更新時間:2025-08-29 (世界標準時間)。"],[[["\u003cp\u003eML Kit's Face Detection API can detect faces and their features in images and videos, but it does not recognize individuals.\u003c/p\u003e\n"],["\u003cp\u003eIt can be used for tasks such as adding effects to photos, creating avatars, and building interactive applications that respond to facial expressions.\u003c/p\u003e\n"],["\u003cp\u003eThe API provides facial feature coordinates, contours, expression detection (like smiling), and face tracking across video frames.\u003c/p\u003e\n"],["\u003cp\u003eFace detection happens on the device and is fast enough for real-time applications.\u003c/p\u003e\n"]]],[],null,["With ML Kit's face detection API, you can detect faces in an image, identify\nkey facial features, and get the contours of detected faces. Note that the API\n*detects faces* , it does not *recognize people* .\n\nWith face detection, you can get the information you need to perform tasks like\nembellishing selfies and portraits, or generating avatars from a user's photo.\nBecause ML Kit can perform face detection in real time, you can use it in\napplications like video chat or games that respond to the player's expressions.\n\n[iOS](/ml-kit/vision/face-detection/ios)\n[Android](/ml-kit/vision/face-detection/android)\n\nKey capabilities\n\n- **Recognize and locate facial features** Get the coordinates of the eyes, ears, cheeks, nose, and mouth of every face detected.\n- **Get the contours of facial features** Get the contours of detected faces and their eyes, eyebrows, lips, and nose.\n- **Recognize facial expressions** Determine whether a person is smiling or has their eyes closed.\n- **Track faces across video frames** Get an identifier for each unique detected face. The identifier is consistent across invocations, so you can perform image manipulation on a particular person in a video stream.\n- **Process video frames in real time** Face detection is performed on the device, and is fast enough to be used in real-time applications, such as video manipulation.\n\nExample results\n\nExample 1\n\nFor each face detected:\n\n| Face 1 of 3 ||\n|---------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| **Bounding polygon** | (884.880004882812, 149.546676635742), (1030.77197265625, 149.546676635742), (1030.77197265625, 329.660278320312), (884.880004882812, 329.660278320312) |\n| **Angles of rotation** | Y: -14.054030418395996, Z: -55.007488250732422 |\n| **Tracking ID** | 2 |\n| **Facial landmarks** | |---------------------|--------------------------------------| | **Left eye** | (945.869323730469, 211.867126464844) | | **Right eye** | (971.579467773438, 247.257247924805) | | **Bottom of mouth** | (907.756591796875, 259.714477539062) | ... etc. |\n| **Feature probabilities** | |--------------------|---------------------| | **Smiling** | 0.88979166746139526 | | **Left eye open** | 0.98635888937860727 | | **Right eye open** | 0.99258323386311531 | |\n\nExample 2 (face contour detection)\n\nWhen you have face contour detection enabled, you also get a list of points\nfor each facial feature that was detected. These points represent the shape of\nthe feature. The following image illustrates how these points map to a face.\nClick the image to enlarge it:\n\n[](/static/ml-kit/vision/face-detection/images/face_contours.svg)\n\n| Facial feature contours ||\n|----------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| **Nose bridge** | (505.149811, 221.201797), (506.987122, 313.285919) |\n| **Left eye** | (404.642029, 232.854431), (408.527283, 231.366623), (413.565796, 229.427856), (421.378296, 226.967682), (432.598755, 225.434143), (442.953064, 226.089508), (453.899811, 228.594818), (461.516418, 232.650467), (465.069580, 235.600845), (462.170410, 236.316147), (456.233643, 236.891602), (446.363922, 237.966888), (435.698914, 238.149323), (424.320740, 237.235168), (416.037720, 236.012115), (409.983459, 234.870300) |\n| **Top of upper lip** | (421.662048, 354.520813), (428.103882, 349.694061), (440.847595, 348.048737), (456.549988, 346.295532), (480.526489, 346.089294), (503.375702, 349.470459), (525.624634, 347.352783), (547.371155, 349.091980), (560.082031, 351.693268), (570.226685, 354.210175), (575.305420, 359.257751) |\n| (etc.) | |"]]