目录

class info
com.huawei.hms.mlsdk.face.MLFaceAnalyzer

Represents the face analyzer,which detects faces (MLFace) in a supplied image.A face analyzer can be created using 

MLAnalyzerFactory.getInstance().getFaceAnalyzer() or MLAnalyzerFactory.getInstance().getFaceAnalyzer (MLFaceAnalyzerSetting).

The former uses the default configuration, and the latter uses the customized configuration.

Public Method Summary

Return typeMethod name
android.util.SparseArray<MLFace>analyseFrame(MLFrame frame)
com.huawei.hmf.tasks.Task<List<MLFace>>asyncAnalyseFrame(MLFrame frame)
booleanisAvailable()
voidstop()throws IOException

Public Methods

Method
public final android.util.SparseArray<MLFace> analyseFrame(MLFrame frame)
Detects faces in a supplied image in synchronous call mode.

Parameters

Parameter nameParameter desc
frameImage to be detected.


Return

Typedesc
android.util.SparseArray<MLFace>Returns a list of face objects.
Method
public com.huawei.hmf.tasks.Task<List<MLFace>> asyncAnalyseFrame(MLFrame frame)
Detects faces in a supplied image in asynchronous call mode.

Parameters

Parameter nameParameter desc
frameImage to be detected.


Return

Typedesc
com.huawei.hmf.tasks.Task<List<MLFace>>

Returns the asynchronous task that encapsulates the detection result.

For details about the usage, see the sample code.


Sample Code

  1. // Create a face analyzer that uses the default configuration.
  2. MLFaceAnalyzer analyzer = MLAnalyzerFactory.getInstance().getFaceAnalyzer();
  3. // Create an MLFrame bMLFrame the bitmap. It is recommended that the image size be greater than or equal to 320 x 320 and smaller than or equal to 1920 x 1920.
  4. MLFrame frame = MLFrame.fromBitmap(bitmap);
  5. Task<List<MLFace>> task = analyzer.asyncAnalyseFrame(frame);
  6. task.addOnSuccessListener(new OnSuccessListener<List<MLFace>>() {
  7.   public void onSuccess(List<MLFace> faces) {
  8.      // Process the detection result.
  9.   }
  10. }).addOnFailureListener(new OnFailureListener() {
  11.   public void onFailure(Exception e) {
  12.      // Detection failure.
  13.   }
  14. });
Method
public boolean isAvailable()
Queries whether the analyzer is available, that is, whether all required resources (algorithm model) are loaded properly.

Return

Typedesc
boolean

Indicates whether the analyzer is available.

true: available.

false: unavailable.
Method
public void stop() throws IOException
Releases the resources used by the analyzer.

Throws

Exception nameException desc
IOExceptionInput/output exception.