ML Kit provides two SDK integration modes: full SDK and base SDK. You can select either one based on your needs. For details, please refer to Full SDK and base SDK in Overview.
In this mode, you need to integrate the base SDK and then one or more required language model packages. The following table describes the supported language model packages.
Package Type | Package Name | SDK Size | Storage Position |
Latin-based language model package | ml-computer-vision-ocr-latin-model | 374K | com.huawei.hms:ml-computer-vision-ocr-latin-model:2.0.0.300 |
Japanese and Korean model package | ml-computer-vision-ocr-jk-model | 2.2M | com.huawei.hms:ml-computer-vision-ocr-jk-model:2.0.0.300 |
| Chinese and English model packages | ml-computer-vision-ocr-cn-model | 2.4M | com.huawei.hms:ml-computer-vision-ocr-cn-model:2.0.0.300 |
When you integrate a language model package, the algorithm package is automatically downloaded (about 6.9 MB). The algorithm package is downloaded only once even when you integrate multiple language model packages.
The sample code for this mode is as follows:
- dependencies{
- // Import the base SDK.
- implementation 'com.huawei.hms:ml-computer-vision-ocr:2.0.0.300'
- // Import the Latin-based language model package.
- implementation 'com.huawei.hms:ml-computer-vision-ocr-latin-model:2.0.0.300'
- // Import the Japanese and Korean model package.
- implementation 'com.huawei.hms:ml-computer-vision-ocr-jk-model:2.0.0.300'
- // Import the Chinese and English model package.
- implementation 'com.huawei.hms:ml-computer-vision-ocr-cn-model:2.0.0.300'
- }
The sample code is as follows:
- dependencies{
- implementation 'com.huawei.hms:ml-computer-vision-ocr:2.0.0.300'
- }
After integrating the SDK in either mode, add the following configuration to the file header:
- apply plugin: 'com.huawei.agconnect'
Add the configuration following the configuration item below:
- apply plugin: 'com.android.application'
Automatically Updating the Latest Machine Learning Model
To use on-device text recognition, add the following statements to the AndroidManifest.xml file. After a user installs your app from HUAWEI AppGallery, the machine learning model is automatically updated to the user's device.
- <manifest
- ...
- <meta-data
- android:name="com.huawei.hms.ml.DEPENDENCY"
- android:value= "ocr"/>
- ...
- </manifest>