| class info |
| com.huawei.hms.mlsdk.classification.MLImageClassificationAnalyzer |
图像分类器:用于在提供的图像中查找图像类别(MLImageClassification)。 图像分类器有两种类型,一种是设备端分类器,即在设备上运行分类模型,返回分类结果;另一种是云端分类器,即调用云端API进行分类,分类模型在云端运行。 创建设备端图像分类器有两种方式: MLAnalyzerFactory.getInstance().getLocalImageClassificationAnalyzer()和MLAnalyzerFactory.getInstance().getLocalImageClassificationAnalyzer(MLLocalClassificationAnalyzerSetting), 前者使用MLLocalClassificationAnalyzerSetting中设置的默认配置,后者可自定义配置项。 |
- // 创建使用默认配置的设备端图像分类器。
- MLImageClassificationAnalyzer analyzer = MLAnalyzerFactory.getInstance().getLocalImageClassificationAnalyzer();
- // 也可以通过用同样的方式创建云端图像分类器。
- // MLImageClassificationAnalyzer analyzer = MLAnalyzerFactory.getInstance().getRemoteImageClassificationAnalyzer();
- // 通过bitmap创建MLFrame。建议图片尺寸不小于224*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) {
- // 对分类结果进行处理
- }
- }).addOnFailureListener(new OnFailureListener() {
- public void onFailure(Exception e) {
- // 处理失败
- }
- });
| Type | Name | Desc |
| int | TYPE_LOCAL | 图像分类器使用设备端模型。 |
| int | TYPE_REMOTE | 图像分类器使用云端模型。 |
| 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 |
| 图像分类器使用设备端模型。 |
| Constant Value: 0 |
| Constant |
| public static final int TYPE_REMOTE |
| 图像分类器使用云端模型。 |
| Constant Value: 1 |
| Method |
| public android.util.SparseArray<MLImageClassification> analyseFrame(MLFrame frame) |
| 对图像进行分类,同步处理方式。 |
Parameters
| Parameter name | Parameter desc |
| frame | 待分类图像。 |
Return
| Type | desc |
| android.util.SparseArray<MLImageClassification> | 返回分类结果集合。 |
| Method |
| public com.huawei.hmf.tasks.Task<List<MLImageClassification>> asyncAnalyseFrame(MLFrame frame) |
| 对图像进行分类,异步处理方式。 |
Parameters
| Parameter name | Parameter desc |
| frame | 待分类图像。 |
Return
| Type | desc |
| com.huawei.hmf.tasks.Task<List<MLImageClassification>> | 返回分类结果的异步任务对象,使用方式参考示例代码。 |
| Method |
| public int getAnalyzerType() |
| 获取图像分析器类型。 |
Return
| Type | desc |
| int | 返回图像分析器类型。 0:TYPE_LOCAL,表示图像分类器使用设备端模型; 1:TYPE_REMOTE,表示图像分类器使用云端模型。 |
| Method |
| public void stop() throws IOException |
| 关闭分类器所使用的资源。 |
Throws
| Exception name | Exception desc |
| IOException | 发生输入/输出异常。 |