| 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. |
| Return type | Method name |
| android.util.SparseArray<MLFace> | analyseFrame(MLFrame frame) |
| com.huawei.hmf.tasks.Task<List<MLFace>> | asyncAnalyseFrame(MLFrame frame) |
| boolean | isAvailable() |
| void | stop()throws IOException |
| Method |
| public final android.util.SparseArray<MLFace> analyseFrame(MLFrame frame) |
| Detects faces in a supplied image in synchronous call mode. |
Parameters
| Parameter name | Parameter desc |
| frame | Image to be detected. |
Return
| Type | desc |
| 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 name | Parameter desc |
| frame | Image to be detected. |
Return
| Type | desc |
| 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
- // Create a face analyzer that uses the default configuration.
- MLFaceAnalyzer analyzer = MLAnalyzerFactory.getInstance().getFaceAnalyzer();
- // 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.
- MLFrame frame = MLFrame.fromBitmap(bitmap);
- Task<List<MLFace>> task = analyzer.asyncAnalyseFrame(frame);
- task.addOnSuccessListener(new OnSuccessListener<List<MLFace>>() {
- public void onSuccess(List<MLFace> faces) {
- // Process the detection result.
- }
- }).addOnFailureListener(new OnFailureListener() {
- public void onFailure(Exception e) {
- // Detection failure.
- }
- });
| Method |
| public boolean isAvailable() |
| Queries whether the analyzer is available, that is, whether all required resources (algorithm model) are loaded properly. |
Return
| Type | desc |
| 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 name | Exception desc |
| IOException | Input/output exception. |