Face Detection

enableFaceDetection

Enables or disables local user face detection.

public abstract int enableFaceDetection(boolean enabled);

Timing

You must call this method after starting the camera using startPreview or enableVideo.

Parameters

enabled
Whether to enable local user face detection:
  • true: Enable face detection.
  • false: (default) Disable face detection.

Return Values

  • 0: Success.
  • < 0: Failure.

onFacePositionChanged

Reports local user's face detection result.

public void onFacePositionChanged(int imageWidth, int imageHeight, AgoraFacePositionInfo[] faceRectArr)
After calling enableFaceDetection(true) to enable face detection, you can get the following information in real time:
  • Width and height of the local video.
  • Position of the face in the local view.
  • Distance between the face and the screen. This value is calculated based on the local video size and face position.
Note:
  • This callback is triggered immediately when the face in front of the camera disappears. When no face is detected, to reduce power consumption, the callback frequency is reduced.
  • When the face is close to the screen, the SDK stops triggering this callback.
  • On Android, the reported distance value may differ slightly from the actual distance, so it is not recommended for precise calculations.

Parameters

imageWidth
Width of the video image captured by the local camera (in pixels).
imageHeight
Height of the video image captured by the local camera (in pixels).
faceRectArr
Detected face information. The array length depends on the number of detected faces and may be 0, indicating no face detected in front of the camera. See AgoraFacePositionInfo.