# 人脸检测 (/zh-CN/api-reference/rtc/ios/video/video-prenpro/face-detection) > For AI agents: see the complete documentation index at [llms.txt](/llms.txt). ## enableFaceDetection: [#enablefacedetection] 启用或关闭本地用户的人脸检测功能。 ```objc - (int)enableFaceDetection:(BOOL)enable NS_SWIFT_NAME(enableFaceDetection(_:)); ``` 你可以通过该方法启用或关闭本地用户的人脸检测功能。该方法需要在摄像头启动后调用,例如调用 [startPreview:](/zh-CN/api-reference/rtc/ios/video/video-basic#api_irtcengine_startpreview2) 或 [enableVideo](/zh-CN/api-reference/rtc/ios/video/video-basic#api_irtcengine_enablevideo) 方法后。启用后,SDK 会通过 [rtcEngine\:facePositionDidChangeWidth\:previewHeight\:faces:](/zh-CN/api-reference/rtc/ios/video/video-prenpro/face-detection#callback_irtcengineeventhandler_onfacepositionchanged) 回调报告本地用户的人脸信息,包括: - 本地视频的宽度和高度。 - 人脸在本地视图中的位置。 - 人脸与屏幕之间的距离。 ### 调用时机 [#调用时机] 该方法需要在摄像头启动后调用,例如调用 [startPreview:](/zh-CN/api-reference/rtc/ios/video/video-basic#api_irtcengine_startpreview2) 或 [enableVideo](/zh-CN/api-reference/rtc/ios/video/video-basic#api_irtcengine_enablevideo) 方法后。 ### 参数 [#参数] 是否启用本地用户的人脸检测功能: - YES:启用人脸检测。 - NO:(默认)关闭人脸检测。 ### 返回值 [#返回值] - 0:方法调用成功。 - < 0:方法调用失败。详见[错误码](/zh-CN/api-reference/rtc/error-code)了解详情和解决建议。 ### 所属接口类 [#所属接口类] - [AgoraRtcEngineKit](/zh-CN/api-reference/rtc/ios/rtc-interface-class#class_irtcengine) ## rtcEngine\:facePositionDidChangeWidth\:previewHeight\:faces: [#rtcenginefacepositiondidchangewidthpreviewheightfaces] 上报本地用户的人脸检测结果。 ```objc - (void)rtcEngine:(AgoraRtcEngineKit* _Nonnull)engine facePositionDidChangeWidth:(int)width previewHeight:(int)height faces:(NSArray* _Nullable)faces NS_SWIFT_NAME(rtcEngine(_:facePositionDidChangeWidth:previewHeight:faces:)); ``` :::info[自从] 自 v3.0.1 版本新增。 ::: 调用 [enableFaceDetection:](/zh-CN/api-reference/rtc/ios/video/video-prenpro/face-detection#api_irtcengine_enablefacedetection) 传入 YES 启用人脸检测后,你可以实时获取本地用户的以下信息: - 本地视频的宽度和高度。 - 人脸在本地视图中的位置。 - 人脸与屏幕之间的距离。 该距离值是基于本地视频尺寸和人脸位置的拟合计算结果。 :::note 注: - 当检测到摄像头前的人脸消失时,会立即触发该回调。当未检测到人脸时,为降低本地设备的功耗,该回调的触发频率会降低。 - 当人脸靠近屏幕时,SDK 会停止触发该回调。 ::: ### 触发时机 [#触发时机] 该回调在检测到人脸位置或数量发生变化时被触发。 ### 参数 [#参数-1] [AgoraRtcEngineKit](/zh-CN/api-reference/rtc/ios/rtc-interface-class#class_irtcengine) 对象。详见 [AgoraRtcEngineKit](/zh-CN/api-reference/rtc/ios/rtc-interface-class#class_irtcengine)。 本地摄像头采集的视频图像的宽度(像素)。 本地摄像头采集的视频图像的高度(像素)。 检测到的人脸信息,详见 [AgoraFacePositionInfo](/zh-CN/api-reference/rtc/ios/class-agorafacepositioninfo)。该回调中返回的 [AgoraFacePositionInfo](/zh-CN/api-reference/rtc/ios/class-agorafacepositioninfo) 数组数量取决于检测到的人脸数量。数组长度可能为 0,表示摄像头前未检测到人脸。 ### 所属接口类 [#所属接口类-1] - [AgoraRtcEngineDelegate](/zh-CN/api-reference/rtc/ios/rtc-interface-class#class_irtcengineeventhandler)