当前位置:网站首页>Machine learning makes character recognition easier: kotlin+mvvm+ Huawei ml Kit
Machine learning makes character recognition easier: kotlin+mvvm+ Huawei ml Kit
2022-07-29 05:50:00 【Quantify NPC】
brief introduction
The process that computers can obtain information from images or video streams belongs to the field of computer vision .
Text recognition service is a part of computer vision . It is also the hottest AI application at present , Text recognition services can recognize receipts 、 Business card 、 Documents, photos and other pictures with text , Extract the text information . Turn on the camera and you can easily convert the text in pictures or real scenes into text messages .
Use scenarios
- Under the express delivery scenario , By identifying the uploaded pictures , Can quickly send the recipient's name 、 Telephone 、 Fill in the corresponding position with important information such as the recipient's address
- Combine the translation function to achieve real-time photo translation , Facing the menu that I didn't understand , Unreadable road signs, etc , Use this function , Let users in foreign countries do not have to worry about not understanding words , We have written the relevant code , You can visit the blog to view the specific implementation process
https://blog.csdn.net/weixin_38132951/article/details/107352702 - It is often used pdf Document transfer word, In essence, it also uses the ability of text recognition . meanwhile , In daily life, sometimes you need to extract the text in the picture and send it to your friends or write it in a memo .
Ability demonstration
First, let's take a look at using Huawei MLKit Text recognition ability .
Function description
Identify languages
This service can support both device side and cloud side , However, the types of characters it can recognize are different . When calling the device interface , Only Chinese can be recognized ( Simplified Chinese character )、 Japanese 、 Korean 、 Latin characters ( For the supported Latin characters, see the Latin characters supported by the character recognition client ). When calling the cloud interface , Can recognize Chinese ( Simplified Chinese character )、 english 、 Spanish 、 Portuguese 、 Italian 、 German 、 French 、 ru 、 Japanese 、 Korean 、 Polish 、 Finnish 、 Norwegian 、 Swedish 、 Danish 、 Turkish 、 Thai 、 arabic 、 Hindi 、 Indonesian and other languages .
Text recognition features | Text recognition features |
---|---|
End side | Supporting 、 Japan 、 Han 、 Latin characters |
Cloud side | in 、 Britain 、 Law 、 In the west 、 Thai, etc 19 Languages |
Tilt recognition | 30 It can still be recognized in the case of degree inclination |
Curved text support | Support 45 Degree bending can still be successfully identified |
Text tracking | The end side supports tracking |
Recognition mode
The service supports static image recognition and dynamic video stream recognition , Synchronous and asynchronous call methods , By providing a wealth of API, It can help developers quickly build various text recognition applications .
See the official website of Huawei developer Alliance for details :
https://developer.huawei.com/consumer/cn/doc/development/HMSCore-Guides/text-recognition-0000001050040053
Integration steps
step 1: stay Android Studio New construction in China
step 2: Select dependencies according to project requirements
// Import the base SDK.
implementation 'com.huawei.hms:ml-computer-vision-ocr:1.0.3.300'
// Import the Latin-based language model package.
implementation 'com.huawei.hms:ml-computer-vision-ocr-latin-model:1.0.3.315'
// Import the Japanese and Korean model package.
implementation 'com.huawei.hms:ml-computer-vision-ocr-jk-model:1.0.3.300'
// Import the Chinese and English model package.
implementation 'com.huawei.hms:ml-computer-vision-ocr-cn-model:1.0.3.300'
Here's each of them SDK Size
Package type | Package name | Bag size |
---|---|---|
Latin model | ml-computer-vision-ocr-latin-model | 952 KB |
Japanese Korean model | ml-computer-vision-ocr-jk-model | 2.14 MB |
Chinese and English models | ml-computer-vision-ocr-cn-model | 3.46 MB |
If you want a lean version, use the following dependencies
implementation 'com.huawei.hms:ml-computer-vision-ocr:1.0.3.300'
Automatically update machine learning models
<meta-data
android:name="com.huawei.hms.ml.DEPENDENCY"
android:value="ocr" />
stay manifest Add the following permissions to the file
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.INTERNET" />
Let's jump to TextRecognitionViewModel Class , In this class , We received a bitmap containing the user image .
Here is what you can use to call text recognition API And get the String Code of response .
fun textRecognition() {
val setting = MLRemoteTextSetting.Factory()
.setTextDensityScene(MLRemoteTextSetting.OCR_LOOSE_SCENE)
.setLanguageList(object : ArrayList<String?>() {
init {
this.add("zh")
this.add("en")
this.add("hi")
this.add("fr")
this.add("de")
}
})
.setBorderType(MLRemoteTextSetting.ARC)
.create()
val analyzer = MLAnalyzerFactory.getInstance().getRemoteTextAnalyzer(setting)
val frame = MLFrame.fromBitmap(bitmap.value)
val task = analyzer.asyncAnalyseFrame(frame)
task.addOnSuccessListener {
result.value = it.stringValue
}.addOnFailureListener {
result.value = "Exception occurred"
}
}
I want to use cloud services , So choose MLRemoteTextSetting()
According to the density of characters , We can setTextDensityScene() Set to OCR_LOOSE_SCENE or OCR_COMPACT_SCENE
Once the density is set , We will pass setLanguageList () Set the text language .
We can pass on a ArrayList Give it a collection object of . I have added 5 Languages , But you can add languages as needed .
MLRemoteTextSetting.ARC: Returns the vertices of the polygon boundary in arc format .
Now? , Our customization MLRemoteTextSetting The object is ready , We can pass it on to MLTextAnalyzer object .
The next step is to create a MLFrame
**· MLFrame frame= MLFrame.fromBitmap(bitmap);**
On parser object , We're going to call asyncAnalyseFrame ( frame ) And provide our recently created MLFrame.
This will generate a Task object , On this object , You will get 2 A callback .
on success
onFailure
Can be in **onSuccess() Save new resources in , And pass analyzer.stop()** Method to stop the parser , Release detection resources .
Just in case , You want to use only the following changes in the device model .
MLTextAnalyzer analyzer = MLAnalyzerFactory.getInstance().getLocalTextAnalyzer();
MLLocalTextSetting setting = new MLLocalTextSetting.Factory()
.setOCRMode(MLLocalTextSetting.OCR_DETECT_MODE)
.setLanguage("en")
.create();
Related links
github:
https://github.com/HMS-MLKit/HUAWEI-HMS-MLKit-Sample/tree/master/MLKit-Sample
Developer alliance development guidance document :
https://developer.huawei.com/consumer/cn/doc/development/HMSCore-Guides-V5/text-recognition-0000001050040053-V5
Example demo:
https://developer.huawei.com/consumer/cn/doc/development/HMSCore-Examples-V5/sample-code-0000001050265470-V5
边栏推荐
猜你喜欢
Plato Farm有望通过Elephant Swap,进一步向外拓展生态
完全去中心化的编程模式,不需要服务器,也不需要ip,就像一张漫无目的的网络、四处延伸
DAY6:利用 PHP 编写登陆页面
与开源项目同步开发& CodeReview & Pull Request & fork怎么拉取原始仓库
XDFS&中国日报社在线协同编辑平台典型案例
华为2020校招笔试编程题 看这篇就够了(下)
C# 判断用户是手机访问还是电脑访问
The LAAS protocol of defi 2.0 is the key to revitalizing the development of defi track
Masscan tutorial
我的理想工作,码农的绝对自由支配才是最重要的——未来创业的追求
随机推荐
“山东大学移动互联网开发技术教学网站建设”项目实训日志一
与开源项目同步开发& CodeReview & Pull Request & fork怎么拉取原始仓库
华为2020校招笔试编程题 看这篇就够了(下)
What is sqlmap and how to use it
与张小姐的春夏秋冬(2)
Okaleido Tiger 7.27日登录Binance NFT,首轮已获不俗成绩
Shanzhai coin Shib has a US $548.6 million stake in eth whale's portfolio - traders should be on guard
“山东大学移动互联网开发技术教学网站建设”项目实训日志三
超简单集成HMS ML Kit 人脸检测实现可爱贴纸
win10+opencv3.2+vs2015配置
农村品牌建设给年轻人的一些机会
量化开发必掌握的30个知识点【什么是分笔逐笔数据】?
MOVE PROTOCOL全球健康宣言,将健康运动进行到底
Training log II of the project "construction of Shandong University mobile Internet development technology teaching website"
Fantom (FTM) 价格将在未来几天飙升 20%
"Shandong University mobile Internet development technology teaching website construction" project training log V
中海油集团,桌面云&网盘存储系统应用案例
识变!应变!求变!
IDEA使用JDBC连接MySQL数据库个人详细教程
Novice introduction: download from PHP environment to thinkphp6 framework by hand