# 人脸检测 (/zh-CN/api-reference/rtc/unity/video/video-prenpro/face-detection)
> For AI agents: see the complete documentation index at [llms.txt](/llms.txt).
## EnableFaceDetection [#enablefacedetection]
开启/关闭本地人脸检测。
```csharp
public abstract int EnableFaceDetection(bool enabled);
```
### 调用时机 [#调用时机]
该方法需要在相机启动(如通过调用 [StartPreview [2/2]](/zh-CN/api-reference/rtc/unity/video/video-basic#api_irtcengine_startpreview2) 或 [EnableVideo](/zh-CN/api-reference/rtc/unity/video/video-basic#api_irtcengine_enablevideo) 实现)后调用。
### 相关回调 [#相关回调]
成功调用该方法后,SDK 会触发 [OnFacePositionChanged](/zh-CN/api-reference/rtc/unity/video/video-prenpro/face-detection#callback_irtcengineeventhandler_onfacepositionchanged) 回调向你报告人脸检测的信息:
- 摄像头采集的画面大小
- 人脸在 view 中的位置
- 人脸距设备屏幕的距离
### 参数 [#参数]
是否开启人脸检测:
- true:开启人脸检测。
- false:(默认)关闭人脸检测。
### 返回值 [#返回值]
- 0: 方法调用成功。
- < 0: 方法调用失败。详见[错误码](/zh-CN/api-reference/rtc/error-code)了解详情和解决建议。
### 所属接口类 [#所属接口类]
- [IRtcEngine](/zh-CN/api-reference/rtc/unity/rtc-interface-class#class_irtcengine)
## OnFacePositionChanged [#onfacepositionchanged]
报告本地人脸检测结果。
```csharp
public virtual void OnFacePositionChanged(int imageWidth, int imageHeight, Rectangle vecRectangle, int[] vecDistance, int numFaces) {}
```
调用 `EnableFaceDetection(true)` 开启本地人脸检测后,你可以通过该回调实时获取以下人脸检测的信息:
- 摄像头采集的画面大小
- 人脸在 view 中的位置
- 人脸距设备屏幕的距离
其中,人脸距设备屏幕的距离由 SDK 通过摄像头采集的画面大小和人脸在 view 中的位置拟合计算得出。
:::note
注:
- 该回调仅适用于 Android 和 iOS 平台。
- 当检测到摄像头前的人脸消失时,该回调会立刻触发;在无人脸的状态下,该回调触发频率会降低,以节省设备耗能。
- 当人脸距离设备屏幕过近时,SDK 不会触发该回调。
:::
### 参数 [#参数-1]
摄像头采集画面的宽度 (px)。
摄像头采集画面的高度 (px)。
检测到的人脸信息。详见 [Rectangle](/zh-CN/api-reference/rtc/unity/class-rectangle)。
人脸和设备屏幕之间的距离 (cm)。
检测的人脸数量。如果为 0,则表示没有检测到人脸。
### 所属接口类 [#所属接口类-1]
- [IRtcEngineEventHandler](/zh-CN/api-reference/rtc/unity/rtc-interface-class#class_irtcengineeventhandler)