Usage of ML Kit Services in Flutter

Efnan Akkuş
Huawei Developers
Published in
5 min readSep 15, 2020

Hello everyone, in this article, we’ll develop a flutter application using the Huawei Ml kit’s text recognition, translation and landmark services. Lets get start it.

About the Service

Flutter ML Plugin enables communication between the HMS Core ML SDK and Flutter platform. This plugin exposes all functionality provided by the HMS Core ML SDK.

HUAWEI ML Kit allows your apps to easily leverage Huawei’s long-term proven expertise in machine learning to support diverse artificial intelligence (AI) applications throughout a wide range of industries. Thanks to Huawei’s technology accumulation, ML Kit provides diversified leading machine learning capabilities that are easy to use, helping you develop various AI apps.

Configure your project on AppGallery Connect

Registering a Huawei ID

You need to register a Huawei ID to use the plugin. If you don’t have one, follow the instructions here.

Preparations for Integrating HUAWEI HMS Core

First of all, you need to integrate Huawei Mobile Services with your application. I will not get into details about how to integrate your application but you can use this tutorial as step by step guide.

Integrating the Flutter Ml Plugin

1. Download the ML Kit Flutter Plugin and decompress it.

2. On your Flutter project directory find and open your pubspec.yaml file and add library to dependencies to download the package from pub.dev. Or if you downloaded the package from the HUAWEI Developer website, specify the library path on your local device. For both ways, after running pub get command, the plugin will be ready to use.

1. Text Recognition

The text recognition service extracts text from images of receipts, business cards, and documents. This service is widely used in office, education, transit, and other apps. For example, you can use this service in a translation app to extract text in a photo and translate the text, improving user experience.

This service can run on the cloud or device, but the supported languages differ in the two scenarios. On-device APIs can recognize text in Simplified Chinese, Japanese, Korean, and Latin-based languages (refer to Latin Script Supported by On-device Text Recognition). When running on the cloud, the service can recognize text in languages such as Simplified Chinese, English, Spanish, Portuguese, Italian, German, French, Russian, Japanese, Korean, Polish, Finnish, Norwegian, Swedish, Danish, Turkish, Thai, Arabic, Hindi, and Indonesian.

Remote Text Analyzer

The text analyzer is on the cloud, which runs a detection model on the cloud after the cloud API is called.

Implementation Procedure

Create an MlTextSettings object and set desired values. The path is mandatory.

Then call analyzeRemotely method by passing the MlTextSettings object you’ve created. This method returns an MlText object on a successful operation. Otherwise it throws exception.

Here’s the result.

2. Text Translation

The translation service can translate text into different languages. Currently, this service supports offline translation of text in Simplified Chinese, English, German, Spanish, French, and Russian (automatic model download is supported), and online translation of text in Simplified Chinese, English, French, Arabic, Thai, Spanish, Turkish, Portuguese, Japanese, German, Italian, Russian, Polish, Malay, Swedish, Finnish, Norwegian, Danish, and Korean.

Create an MlTranslatorSettings object and set the values. Source text must not be null.

Then call getTranslateResult method by passing the MlTranslatorSettings object you’ve created. This method returns translated text on a successful operation. Otherwise it throws exception.

Here’s the result.

3. Landmark Recognition

The landmark recognition service can identify the names and latitude and longitude of landmarks in an image. You can use this information to create individualized experiences for users. For example, you can create a travel app that identifies a landmark in an image and gives users the location along with everything they need to know about that landmark.

Landmark Recognition

This API is used to carry out the landmark recognition with customized parameters.

Implementation Procedure

Create an MlLandMarkSettings object and set the values. The path is mandatory.

Then call getLandmarkAnalyzeInformation method by passing the MlLandMarkSettings object you’ve created. This method returns an MlLandmark object on a successful operation. Otherwise it throws exception.

Here’s the result.

--

--