目录

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.

Mode 1: Full SDK Integration (Recommended)

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:

  1. dependencies{  
  2.    // Import the base SDK.
  3.    implementation 'com.huawei.hms:ml-computer-vision-ocr:2.0.0.300'
  4.    // Import the Latin-based language model package.
  5.    implementation 'com.huawei.hms:ml-computer-vision-ocr-latin-model:2.0.0.300'
  6.    // Import the Japanese and Korean model package.
  7.    implementation 'com.huawei.hms:ml-computer-vision-ocr-jk-model:2.0.0.300'
  8.    // Import the Chinese and English model package.
  9.    implementation 'com.huawei.hms:ml-computer-vision-ocr-cn-model:2.0.0.300'
  10. }

Mode 2: Base SDK Integration

The sample code is as follows:

  1. dependencies{
  2.    implementation 'com.huawei.hms:ml-computer-vision-ocr:2.0.0.300'
  3. }

Adding Configurations to the File Header

After integrating the SDK in either mode, add the following configuration to the file header:

  1. apply plugin: 'com.huawei.agconnect'
Notice:

Add the configuration following the configuration item below:

  1. 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.

  1. <manifest
  2.    ...
  3.    <meta-data              
  4.        android:name="com.huawei.hms.ml.DEPENDENCY"  
  5.        android:value= "ocr"/>
  6.    ...
  7. </manifest>