当前位置:网站首页>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);
边栏推荐
- 栈:如何实现有效括号的判断?
- 精选综述 | 用于白内障分级/分类的机器学习技术
- tcp为啥是三次握手和四次挥手
- Go notes (1) go language introduction and characteristics
- 【申博攻略】六.如何联系心仪的博导
- [in-depth learning] review pytoch's 19 loss functions
- Managed service network: application architecture evolution in the cloud native Era
- What is the development of block hash quiz game system? Hash quiz game system development (case mature)
- Automatic insertion of captions in word
- WinCC7.5 SP1如何通过交叉索引来寻找变量及其位置?
猜你喜欢

Win11怎么搜索无线显示器?Win11查找无线显示器设备的方法

Win11系统wifi总掉线怎么办?Win11系统wifi总掉线的解决方法

精选综述 | 用于白内障分级/分类的机器学习技术

分析伦敦银走势图的技巧
![[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

Sword finger offer II 80-100 (continuous update)

电脑共享打印机拒绝访问要怎么办

See how Tencent does interface automation testing

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

Alibaba testers use UI automated testing to achieve element positioning
随机推荐
GVM use
Reinforcement learning - learning notes 2 | value learning
伦敦银走势图分析的新方法
Implementation of redis distributed lock
word中使用自动插入题注功能
分析伦敦银走势图的技巧
电脑页面不能全屏怎么办?Win11页面不能全屏的解决方法
jekins初始化密码没有或找不到
Go language notes (2) some simple applications of go
易周金融 | Q1保险行业活跃人数8688.67万人 19家支付机构牌照被注销
go笔记(1)go语言介绍以及特点
阿里测试师用UI自动化测试实现元素定位
Play the music of youth
Idea case shortcut
接口设计时的一些建议
Win11共享文件打不开怎么办?Win11共享文件打不开的解决方法
Flet教程之 08 AppBar工具栏基础入门(教程含源码)
九齐NY8B062D MCU规格书/datasheet
Practice examples to understand JS strong cache negotiation cache
js 闭包