[Huawei Developers] Freemind R:
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/consumer/en/console#/serviceCards/

[IMG="https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/000/001/781/0890052000000001781.20200428224706.34286521955363312007978728204400:50510520105027:2800:E5E000445C412CAB0091E5822B4F82AE3358214FC195B4F50C74BE055254CBDD.png"]https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/000/001/781/0890052000000001781.20200428224706.34286521955363312007978728204400:50510520105027:2800:E5E000445C412CAB0091E5822B4F82AE3358214FC195B4F50C74BE055254CBDD.png[/IMG]

· Access HUAWEI AppGallery

[IMG="https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/000/001/781/0890052000000001781.20200428224721.38795798692712854317463844513942:50510520105027:2800:BFA90A26CB00249D4EC2083012616BE7B1B9568A729C383E0FE5C300AA8FBB56.png"]https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/000/001/781/0890052000000001781.20200428224721.38795798692712854317463844513942:50510520105027:2800:BFA90A26CB00249D4EC2083012616BE7B1B9568A729C383E0FE5C300AA8FBB56.png[/IMG]

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

[IMG="https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/000/001/781/0890052000000001781.20200428224730.48293378533930871930713118914933:50510520105027:2800:45D8D6FEE31BBFA98AC11356C09DFC9908A11ADFC76E936FB615D09D9371E919.png"]https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/000/001/781/0890052000000001781.20200428224730.48293378533930871930713118914933:50510520105027:2800:45D8D6FEE31BBFA98AC11356C09DFC9908A11ADFC76E936FB615D09D9371E919.png[/IMG]

· Access the Develop section and click on Manage APIs

[IMG="https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/000/001/781/0890052000000001781.20200428224742.83002028814108607586079812269688:50510520105027:2800:F2546D9C763DC546FC84A34B7B7CD0AB2A13DA62951D40651DD9BD0FD8E13A4D.png"]https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/000/001/781/0890052000000001781.20200428224742.83002028814108607586079812269688:50510520105027:2800:F2546D9C763DC546FC84A34B7B7CD0AB2A13DA62951D40651DD9BD0FD8E13A4D.png[/IMG]

· Enable ML Kit

[IMG="https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/000/001/781/0890052000000001781.20200428224753.95431300263700896243248496039296:50510520105027:2800:CA31080B02CEB8E1E31C1CEEB3AF444C5B0C902CD4AFBD4B98DF0E138C7D975D.png"]https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/000/001/781/0890052000000001781.20200428224753.95431300263700896243248496039296:50510520105027:2800:CA31080B02CEB8E1E31C1CEEB3AF444C5B0C902CD4AFBD4B98DF0E138C7D975D.png[/IMG]

· Set Storage Location

[IMG="https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/000/001/781/0890052000000001781.20200428224808.89897780902782151524534727611698:50510520105027:2800:9707AA2A29A0533EDCEC15FED06244BDC10FC98B24BDCD69F91EB1F390803676.png"]https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/000/001/781/0890052000000001781.20200428224808.89897780902782151524534727611698:50510520105027:2800:9707AA2A29A0533EDCEC15FED06244BDC10FC98B24BDCD69F91EB1F390803676.png[/IMG]

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

[IMG="https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/000/001/781/0890052000000001781.20200428224820.40345783320945627025596066164186:50510520105027:2800:25C548F46F24737BEADBF11BDAD3085BEDD34CDF82116D56C198E66D64E9E77D.png"]https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/000/001/781/0890052000000001781.20200428224820.40345783320945627025596066164186:50510520105027:2800:25C548F46F24737BEADBF11BDAD3085BEDD34CDF82116D56C198E66D64E9E77D.png[/IMG]

[IMG="https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/000/001/781/0890052000000001781.20200428224847.18249648237192638279679978719858:50510520105027:2800:44D7F71CE6C746F4DB71D19F6008690F186B6DA62DF5396CDE228CFCF647BA0A.png"]https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/000/001/781/0890052000000001781.20200428224847.18249648237192638279679978719858:50510520105027:2800:44D7F71CE6C746F4DB71D19F6008690F186B6DA62DF5396CDE228CFCF647BA0A.png[/IMG]

· 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’”

[IMG="https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/000/001/781/0890052000000001781.20200428225757.98036520994737654852475838245732:50510520105027:2800:77BAFE05782819AECC03B09D793452E634D0987AB14D496597147E33B7849915.png"]https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/000/001/781/0890052000000001781.20200428225757.98036520994737654852475838245732:50510520105027:2800:77BAFE05782819AECC03B09D793452E634D0987AB14D496597147E33B7849915.png[/IMG]

· Add the SDKs dependencies to your project

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

}”

[IMG="https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/000/001/781/0890052000000001781.20200428224923.23064442944429969566058399124140:50510520105027:2800:5649F763017209150ED30A0BB50C69028D80216C47A31F6A129E2E39757BFD13.png"]https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/000/001/781/0890052000000001781.20200428224923.23064442944429969566058399124140:50510520105027:2800:5649F763017209150ED30A0BB50C69028D80216C47A31F6A129E2E39757BFD13.png[/IMG]

· Add the configuration inside the same build.gradle file

“apply plugin: ‘com.huawei.agconnect’”

[IMG="https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/000/001/781/0890052000000001781.20200428225005.83936656832030433819489353797725:50510520105027:2800:5053A039EBA0882A6642C1865EB597F84ACA78983E58ED4E4905B323CBAD6BF7.png"]https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/000/001/781/0890052000000001781.20200428225005.83936656832030433819489353797725:50510520105027:2800:5053A039EBA0882A6642C1865EB597F84ACA78983E58ED4E4905B323CBAD6BF7.png[/IMG]

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

“<manifest

<meta-data

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

android:value= "ocr"/>

</manifest>”

[IMG="https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/000/001/781/0890052000000001781.20200428225042.21794398287830752816062129173406:50510520105027:2800:1C35B7363A0D69748E9F1F72E07A5B82ABF7E2CEB65738BB40653C17398BB363.png"]https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/000/001/781/0890052000000001781.20200428225042.21794398287830752816062129173406:50510520105027:2800:1C35B7363A0D69748E9F1F72E07A5B82ABF7E2CEB65738BB40653C17398BB363.png[/IMG]

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

[IMG="https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/000/001/781/0890052000000001781.20200428225117.13498008095012117584834985880110:50510520105027:2800:ED097F6F98AE274327C3C2F0CB5B1D0AF6087A7D40B0B30939A2AC874BC7BC48.png"]https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/000/001/781/0890052000000001781.20200428225117.13498008095012117584834985880110:50510520105027:2800:ED097F6F98AE274327C3C2F0CB5B1D0AF6087A7D40B0B30939A2AC874BC7BC48.png[/IMG]

This is not the end. For more information about this article, you can visit HUAWEI Developer Forum.