当前位置:网站首页>HMS Core 机器学习服务
HMS Core 机器学习服务
2022-07-04 19:44:00 【Just_Paranoid】
机器学习服务(ML Kit)提供机器学习套件,为开发者使用机器学习能力开发各类应用,提供优质体验。得益于华为长期技术积累,ML Kit为开发者提供简单易用、服务多样、技术领先的机器学习能力,助力开发者更快更好地开发各类AI应用。
- 文本模块:文本识别、文档识别、身份证识别、银行卡识别、通用卡证识别、文本翻译、语种检测、实时语音识别、语音合成、离线语音合成、音频文件转写、声音识别、文本嵌入、实时语音转写
- 视觉模块:图像分割、对象检测与跟踪、图片分类、地标识别、图像超分辨率、文字图像超分辨率、场景识别、表格识别、文档校正
- 人体模块:人脸检测、3D人脸检测、人体骨骼检测、活体检测、手部关键点识别、手势识别、人脸比对
- 自定义模型的演示Demo
指南:
https://developer.huawei.com/consumer/cn/doc/development/hiai-Guides/service-introduction-0000001050040017
服务依赖列表
https://developer.huawei.com/consumer/cn/doc/development/hiai-Guides/overview-sdk-0000001051070278
文本识别
//1.创建文本分析器MLTextAnalyzer用于识别图片中的文字,您可以通过MLLocalTextSetting设置识别的语种,不设置语言默认只能识别拉丁字符。
//方式一:使用默认参数配置端侧文本分析器,只能识别拉丁语系文字。
MLTextAnalyzer analyzer = MLAnalyzerFactory.getInstance().getLocalTextAnalyzer();
//方式二:使用自定义参数MLLocalTextSetting配置端侧文本分析器。
MLLocalTextSetting setting = new MLLocalTextSetting.Factory()
.setOCRMode(MLLocalTextSetting.OCR_DETECT_MODE)
// 设置识别语种。
.setLanguage("zh")
.create();
MLTextAnalyzer analyzer = MLAnalyzerFactory.getInstance().getLocalTextAnalyzer(setting);
//2.通过android.graphics.Bitmap创建MLFrame,支持的图片格式包括:jpg/jpeg/png/bmp,建议输入图片长宽比范围:1:2到2:1。
// 通过bitmap创建MLFrame,bitmap为输入的Bitmap格式图片数据。
MLFrame frame = MLFrame.fromBitmap(bitmap);
//3.将生成的MLFrame对象传递给asyncAnalyseFrame方法进行文字识别。
Task<MLText> task = analyzer.asyncAnalyseFrame(frame);
task.addOnSuccessListener(new OnSuccessListener<MLText>() {
@Override
public void onSuccess(MLText text) {
// 识别成功处理。
}
}).addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(Exception e) {
// 识别失败处理。
}
});
//示例代码中使用了异步调用方式,本地文本识别还支持analyseFrame同步调用方式,识别结果以“MLText.Block”数组进行提供
Context context = getApplicationContext();
MLTextAnalyzer analyzer = new MLTextAnalyzer.Factory(context).setLocalOCRMode(MLLocalTextSetting.OCR_DETECT_MODE).setLanguage("zh").create();
SparseArray<MLText.Block> blocks = analyzer.analyseFrame(frame);
//4.识别完成,停止分析器,释放识别资源。
try {
if (analyzer != null) {
analyzer.stop();
}
} catch (IOException e) {
// 异常处理。
}
静态图片检测
//1.创建图片分类分析器。可以通过图像分类自定义类MLLocalClassificationAnalyzerSetting创建分析器。
// 方式一:端侧识别使用自定义参数配置。
MLLocalClassificationAnalyzerSetting setting =
new MLLocalClassificationAnalyzerSetting.Factory()
.setMinAcceptablePossibility(0.8f)
.create();
MLImageClassificationAnalyzer analyzer = MLAnalyzerFactory.getInstance().getLocalImageClassificationAnalyzer(setting);
// 方式二:端侧识别使用默认参数配置。
MLImageClassificationAnalyzer analyzer = MLAnalyzerFactory.getInstance().getLocalImageClassificationAnalyzer();
//2.通过android.graphics.Bitmap创建MLFrame,支持的图片格式包括:jpg/jpeg/png/bmp,建议图片尺寸不小于112*112像素。
// 通过bitmap创建MLFrame,bitmap为输入的Bitmap格式图片数据。
MLFrame frame = MLFrame.fromBitmap(bitmap);
//3.调用asyncAnalyseFrame方法进行图像分类(错误码信息可参见:机器学习服务错误码)。
Task<List<MLImageClassification>> task = analyzer.asyncAnalyseFrame(frame);
task.addOnSuccessListener(new OnSuccessListener<List<MLImageClassification>>() {
@Override
public void onSuccess(List<MLImageClassification> classifications) {
// 识别成功。
// 遍历返回的列表MLImageClassification,获取分类名称等信息。
}
}).addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(Exception e) {
// 识别失败。
// Recognition failure.
try {
MLException mlException = (MLException)e;
// 获取错误码,开发者可以对错误码进行处理,根据错误码进行差异化的页面提示。
int errorCode = mlException.getErrCode();
// 获取报错信息,开发者可以结合错误码,快速定位问题。
String errorMessage = mlException.getMessage();
} catch (Exception error) {
// 转换错误处理。
}
}
});
//4.识别完成,停止分析器,释放检测资源。
try {
if (analyzer != null) {
analyzer.stop();
}
} catch (IOException e) {
// 异常处理。
}
//以上示例代码中使用了异步调用方式,图片分类还支持同步调用使用analyseFrame函数获取检测结果:
SparseArray<MLImageClassification> classifications = analyzer.analyseFrame(frame);
边栏推荐
- Go language notes (2) some simple applications of go
- idea恢复默认快捷键
- Après l'insertion de l'image dans le mot, il y a une ligne vide au - dessus de l'image, et la disposition est désordonnée après la suppression
- 【ISMB2022教程】图表示学习的精准医疗,哈佛大学Marinka Zitnik主讲,附87页ppt
- 奏响青春的乐章
- 电脑怎么保存网页到桌面上使用
- Selected review | machine learning technology for Cataract Classification / classification
- How does wincc7.5 SP1 find variables and their positions through cross indexing?
- Go notes (1) go language introduction and characteristics
- 针对深度学习的“失忆症”,科学家提出基于相似性加权交错学习,登上PNAS
猜你喜欢

Quelques suggestions pour la conception de l'interface

看腾讯大老如何做接口自动化测试

MySQL --- 数据库查询 - 聚合函数的使用、聚合查询、分组查询

接口設計時的一些建議
![[today in history] July 4: the first e-book came out; The inventor of magnetic stripe card was born; Palm computer pioneer was born](/img/0b/73f0d98a6db813e54074abe199ed98.png)
[today in history] July 4: the first e-book came out; The inventor of magnetic stripe card was born; Palm computer pioneer was born

科普达人丨一文看懂阿里云的秘密武器“神龙架构”

测试员的算法面试题-找众数

工厂从自动化到数字孪生,图扑能干什么?

What if the computer page cannot be full screen? The solution of win11 page cannot be full screen

Ten years' experience of byte test engineer directly hits the pain point of UI automation test
随机推荐
Flet tutorial 04 basic introduction to filledtonalbutton (tutorial includes source code)
RFID仓储管理系统解决方案的优点
MySQL --- 数据库查询 - 聚合函数的使用、聚合查询、分组查询
The problem of the maximum difference between the left and right maxima
What is the development of block hash quiz game system? Hash quiz game system development (case mature)
idea大小写快捷键
Flet tutorial 06 basic introduction to textbutton (tutorial includes source code)
MySQL statement execution details
GVM使用
idea恢复默认快捷键
Stack: how to realize the judgment of valid brackets?
go语言笔记(2)go一些简单运用
九齐NY8B062D MCU规格书/datasheet
Four traversal methods of binary tree, as well as the creation of binary tree from middle order to post order, pre order to middle order, pre order to post order, and sequence [specially created for t
【深度学习】一文看尽Pytorch之十九种损失函数
Hash哈希竞猜游戏系统开发如何开发丨哈希竞猜游戏系统开发(多套案例)
Practical examples of node strong cache and negotiation cache
Win11无法将值写入注册表项如何解决?
hash 表的概念及应用
word中使用自动插入题注功能