| class info |
| com.huawei.hms.mlsdk.classification.MLImageClassificationAnalyzer |
Represents the image classification analyzer, which detects the classification (MLImageClassification) of a supplied image. There are two types of image classification analyzers. One is the on-device analyzer, which runs a classification model on the device and returns the classification result. The other is the on-cloud analyzer, which runs a classification model on the cloud after the cloud API is called. An on-device image classification analyzer can be created using MLAnalyzerFactory.getInstance().getLocalImageClassificationAnalyzer() or MLAnalyzerFactory.getInstance().getLocalImageClassificationAnalyzer(MLLocalClassificationAnalyzerSetting). The former uses the default configuration in MLLocalClassificationAnalyzerSetting, and the latter uses the customized configuration. |
- // Create an on-device image classification analyzer that uses the default configuration.
- MLImageClassificationAnalyzer analyzer = MLAnalyzerFactory.getInstance().getLocalImageClassificationAnalyzer();
- // You can also create an on-cloud classification analyzer in a similar way.
- // MLImageClassificationAnalyzer analyzer = MLAnalyzerFactory.getInstance().getRemoteImageClassificationAnalyzer();
- // Create an MLFramMLFrameing the bitmap.It is recommended that the image size be greater than or equal to 224 x 224.
- MLFrame frame = MLFrame.fromBitmap(bitmap);
- Task<List<MLImageClassification>> task = analyzer.asyncAnalyseFrame(frame);
- task.addOnSuccessListener(new OnSuccessListener<List<MLImageClassification>>() {
- public void onSuccess(List<MLImageClassification>classifications) {
- // Process the classification result.
- }
- }).addOnFailureListener(new OnFailureListener() {
- public void onFailure(Exception e) {
- // Processing failure.
- }
- });
| Type | Name | Desc |
| int | TYPE_LOCAL | The image classification analyzer uses an on-device model. |
| int | TYPE_REMOTE | The image classification analyzer uses an on-cloud model. |
| Return type | Method name |
| android.util.SparseArray<MLImageClassification> | analyseFrame(MLFrame frame) |
| com.huawei.hmf.tasks.Task<List<MLImageClassification>> | asyncAnalyseFrame(MLFrame frame) |
| int | getAnalyzerType() |
| void | stop()throws IOException |
| Constant |
| public static final int TYPE_LOCAL |
The image classification analyzer uses an on-device model. Constant value: 0 |
| Constant |
| public static final int TYPE_REMOTE |
The image classification analyzer uses an on-cloud model. Constant value: 1 |
| Method |
| public android.util.SparseArray<MLImageClassification> analyseFrame(MLFrame frame) |
| Classifies images by synchronous processing. |
Parameters
| Parameter name | Parameter desc |
| frame | Image to be classified. |
Return
| Type | desc |
| android.util.SparseArray<MLImageClassification> | Returns a set of classification results. |
| Method |
| public com.huawei.hmf.tasks.Task<List<MLImageClassification>> asyncAnalyseFrame(MLFrame frame) |
| Classifies images by asynchronous processing. |
Parameters
| Parameter name | Parameter desc |
| frame | Image to be classified. |
Return
| Type | desc |
| com.huawei.hmf.tasks.Task<List<MLImageClassification>> | Returns the asynchronous task that encapsulates the classification result. For details about the usage, see the sample code. |
| Method |
| public int getAnalyzerType() |
| Obtains the type of the image classification analyzer. |
Return
| Type | desc |
| int | Returns the type of the image classification analyzer. 0: TYPE_LOCAL, indicating that the image classification analyzer uses an on-device model. 1: TYPE_REMOTE, indicating that the image classification analyzer uses an on-cloud model. |
| Method |
| public void stop() throws IOException |
| Closes the resources used by the image classification analyzer. |
Throws
| Exception name | Exception desc |
| IOException | Input/output exception. |