# 人脸检测 (/zh-CN/api-reference/rtc/android/video/video-prenpro/face-detection) > For AI agents: see the complete documentation index at [llms.txt](/llms.txt). ## enableFaceDetection [#enablefacedetection] 启用或关闭本地用户的人脸检测功能。 ```java public abstract int enableFaceDetection(boolean enabled); ``` ### 调用时机 [#调用时机] 该方法需在调用 `startPreview` 或 [enableVideo](/zh-CN/api-reference/rtc/android/video/video-basic#api_irtcengine_enablevideo) 启动相机后调用。 ### 相关回调 [#相关回调] 启用人脸检测后,SDK 会触发 [onFacePositionChanged](/zh-CN/api-reference/rtc/android/video/video-prenpro/face-detection#callback_irtcengineeventhandler_onfacepositionchanged) 回调,报告本地用户的人脸信息,包括: - 本地视频的宽度和高度。 - 人脸在本地视图中的位置。 - 人脸与屏幕之间的距离。 ### 参数 [#参数] 是否启用本地用户的人脸检测功能: - true:启用人脸检测。 - false:(默认)关闭人脸检测。 ### 返回值 [#返回值] - 0:方法调用成功。 - < 0:方法调用失败。详见[错误码](/zh-CN/api-reference/rtc/error-code)了解详情和解决建议。 ### 所属接口类 [#所属接口类] - [RtcEngine](/zh-CN/api-reference/rtc/android/rtc-interface-class#class_irtcengine) ## onFacePositionChanged [#onfacepositionchanged] 上报本地用户的人脸检测结果。 ```java public void onFacePositionChanged(int imageWidth, int imageHeight, AgoraFacePositionInfo[] faceRectArr) ``` 调用 `enableFaceDetection(true)` 启用人脸检测功能后,你可以实时获取以下信息: - 本地视频的宽度和高度。 - 人脸在本地视图中的位置。 - 人脸与屏幕之间的距离。该距离值基于本地视频尺寸和人脸位置的拟合计算得出。 :::note 注: - 当检测到摄像头前的人脸消失时,会立即触发该回调。当未检测到人脸时,为降低本地设备的功耗,该回调的触发频率会降低。 - 当人脸靠近屏幕时,SDK 会停止触发该回调。 - 在 Android 平台,该回调中上报的距离值可能与实际距离略有偏差,因此不建议用于精确计算。 ::: ### 参数 [#参数-1] 本地摄像头采集的视频图像的宽度(单位为像素)。 本地摄像头采集的视频图像的高度(单位为像素)。 检测到的人脸信息。该数组的长度取决于检测到的人脸数量,可能为 0,表示摄像头前未检测到人脸。详见 [AgoraFacePositionInfo](/zh-CN/api-reference/rtc/android/class-agorafacepositioninfo)。 ### 所属接口类 [#所属接口类-1] - [IRtcEngineEventHandler](/zh-CN/api-reference/rtc/android/rtc-interface-class#class_irtcengineeventhandler)