FORUMS

How to Be Language All-rounder with HUAWEI ML Kit?

46 posts
Thanks Meter: 2
 
By Freemind R, Official Huawei Rep on 20th May 2020, 12:04 PM
Post Reply Email Thread
The original article is from HUAWEI Developer Forum
(forum link: https://forums.developer.huawei.com/forumPortal/en/home)


1. Introduction

Optical Character Recognition is the function to detect and process characters from a determined alphabet. With HUAWEI Text recognition service allows you to extract text from images, documents or any print representation of characters.

This service can run on the cloud or device. If the service needs to scan characters from Simplified Chinese, Japanese, Korean and Latin based language the service can use on Device text recognition.

The cloud service supports languages such as Simplified Chinese, English, Spanish, Portuguese, Italian, German, French, Russian, Japanese, Korean, Polish, Finnish, Norwegian, Swedish, Danish, Turkish, Thai, Arabic and Hindi.

2. Preparations

To enable the ML Kit, It is needed to follow these steps.

· Login to Huawei Developer https://developer.huawei.com/consume.../serviceCards/

https://img.xda-cdn.com/FlO9_r7KRAd_-CWEtlrqyjYjHp0=/https%3A%2F%2Fcommunityfile-dre.op.hicloud.com%2FFileServer%2FgetFile%2Fcmtybbs%2F000%2F001%2F781%2F0890052000000001781.20200428224706.34286521955363312007978728204400%3A50510520105027%3A2800%3AE5E000445C412CAB0091E5822B4F82AE3358214FC195B4F50C74BE055254CBDD.png

· Access HUAWEI AppGallery

https://img.xda-cdn.com/6P19VGz_lreDEjzN28MUPPWDK0o=/https%3A%2F%2Fcommunityfile-dre.op.hicloud.com%2FFileServer%2FgetFile%2Fcmtybbs%2F000%2F001%2F781%2F0890052000000001781.20200428224721.38795798692712854317463844513942%3A50510520105027%3A2800%3ABFA90A26CB00249D4EC2083012616BE7B1B9568A729C383E0FE5C300AA8FBB56.png

· Select My Apps and the select the app you want to integrate the service.

https://img.xda-cdn.com/nNlcgaTtbnakBzk7j6TfiGQHUyA=/https%3A%2F%2Fcommunityfile-dre.op.hicloud.com%2FFileServer%2FgetFile%2Fcmtybbs%2F000%2F001%2F781%2F0890052000000001781.20200428224730.48293378533930871930713118914933%3A50510520105027%3A2800%3A45D8D6FEE31BBFA98AC11356C09DFC9908A11ADFC76E936FB615D09D9371E919.png

· Access the Develop section and click on Manage APIs

https://img.xda-cdn.com/wfUXIR7CnI0njjcL0R869LYT4rc=/https%3A%2F%2Fcommunityfile-dre.op.hicloud.com%2FFileServer%2FgetFile%2Fcmtybbs%2F000%2F001%2F781%2F0890052000000001781.20200428224742.83002028814108607586079812269688%3A50510520105027%3A2800%3AF2546D9C763DC546FC84A34B7B7CD0AB2A13DA62951D40651DD9BD0FD8E13A4D.png

· Enable ML Kit

https://img.xda-cdn.com/pB6FAVe6fjWtl0iXX5nLykr7GPQ=/https%3A%2F%2Fcommunityfile-dre.op.hicloud.com%2FFileServer%2FgetFile%2Fcmtybbs%2F000%2F001%2F781%2F0890052000000001781.20200428224753.95431300263700896243248496039296%3A50510520105027%3A2800%3ACA31080B02CEB8E1E31C1CEEB3AF444C5B0C902CD4AFBD4B98DF0E138C7D975D.png

· Set Storage Location

https://img.xda-cdn.com/ffmUve3GvAhGd12HLGHGuXI_DUo=/https%3A%2F%2Fcommunityfile-dre.op.hicloud.com%2FFileServer%2FgetFile%2Fcmtybbs%2F000%2F001%2F781%2F0890052000000001781.20200428224808.89897780902782151524534727611698%3A50510520105027%3A2800%3A9707AA2A29A0533EDCEC15FED06244BDC10FC98B24BDCD69F91EB1F390803676.png

· Download agconnect-services.json and add it in the app root directory of your Android Studio project

https://img.xda-cdn.com/8JkkNIdfHe7ePBfbb4x6EZjjjFY=/https%3A%2F%2Fcommunityfile-dre.op.hicloud.com%2FFileServer%2FgetFile%2Fcmtybbs%2F000%2F001%2F781%2F0890052000000001781.20200428224820.40345783320945627025596066164186%3A50510520105027%3A2800%3A25C548F46F24737BEADBF11BDAD3085BEDD34CDF82116D56C198E66D64E9E77D.png

https://img.xda-cdn.com/gfosKxuLeD4E4RMY1Y3TmJIXnnY=/https%3A%2F%2Fcommunityfile-dre.op.hicloud.com%2FFileServer%2FgetFile%2Fcmtybbs%2F000%2F001%2F781%2F0890052000000001781.20200428224847.18249648237192638279679978719858%3A50510520105027%3A2800%3A44D7F71CE6C746F4DB71D19F6008690F186B6DA62DF5396CDE228CFCF647BA0A.png

· Open the build.gradle file in the root directory

· Add the maven “maven{url’https://developer.huawei.com/repo/’}” and Classpath “classpath’com.huawei.agconnect:agcp:1.2.1.301’”

https://img.xda-cdn.com/12RG13dgFIKQwPs6NTeYK_iKhls=/https%3A%2F%2Fcommunityfile-dre.op.hicloud.com%2FFileServer%2FgetFile%2Fcmtybbs%2F000%2F001%2F781%2F0890052000000001781.20200428225757.98036520994737654852475838245732%3A50510520105027%3A2800%3A77BAFE05782819AECC03B09D793452E634D0987AB14D496597147E33B7849915.png

· Add the SDKs dependencies to your project

Code:
“dependencies{  

 // 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'

}”
https://img.xda-cdn.com/g_RKBqTvkLFQVEzaU0b3XwgEdyQ=/https%3A%2F%2Fcommunityfile-dre.op.hicloud.com%2FFileServer%2FgetFile%2Fcmtybbs%2F000%2F001%2F781%2F0890052000000001781.20200428224923.23064442944429969566058399124140%3A50510520105027%3A2800%3A5649F763017209150ED30A0BB50C69028D80216C47A31F6A129E2E39757BFD13.png

· Add the configuration inside the same build.gradle file

Code:
“apply plugin: ‘com.huawei.agconnect’”
https://img.xda-cdn.com/Wk1n9bRQBCAm9wQyGA9fy3AadZE=/https%3A%2F%2Fcommunityfile-dre.op.hicloud.com%2FFileServer%2FgetFile%2Fcmtybbs%2F000%2F001%2F781%2F0890052000000001781.20200428225005.83936656832030433819489353797725%3A50510520105027%3A2800%3A5053A039EBA0882A6642C1865EB597F84ACA78983E58ED4E4905B323CBAD6BF7.png

· In the Android Manifest File add the following code to enable your app to automatically update the latest ML models on the device.

Code:
“<manifest

    <meta-data             

        android:name="com.huawei.hms.ml.DEPENDENCY"  

        android:value= "ocr"/>

</manifest>”
https://img.xda-cdn.com/qpbdQdGnebvbIA_1d8XnZdwXJX0=/https%3A%2F%2Fcommunityfile-dre.op.hicloud.com%2FFileServer%2FgetFile%2Fcmtybbs%2F000%2F001%2F781%2F0890052000000001781.20200428225042.21794398287830752816062129173406%3A50510520105027%3A2800%3A1C35B7363A0D69748E9F1F72E07A5B82ABF7E2CEB65738BB40653C17398BB363.png

3. Development
Text recognition from images on the device

1. Need to create the MLTextAnalyzer to recognize text in images. Also set MLLocalTextSetting to specify languages, if none are specified, only Latin-based languages are going to being recognized

https://img.xda-cdn.com/GzzLNXEs53IpSJQytRLJ3lj1U90=/https%3A%2F%2Fcommunityfile-dre.op.hicloud.com%2FFileServer%2FgetFile%2Fcmtybbs%2F000%2F001%2F781%2F0890052000000001781.20200428225117.13498008095012117584834985880110%3A50510520105027%3A2800%3AED097F6F98AE274327C3C2F0CB5B1D0AF6087A7D40B0B30939A2AC874BC7BC48.png

This is not the end. For more information about this article, you can visit HUAWEI Developer Forum.
Post Reply Subscribe to Thread

Tags
huawei ml kit

Guest Quick Reply (no urls or BBcode)
Message:
Previous Thread Next Thread
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes