ML Kit Text Recognition Extension

📊 ML Kit Text Recognition


An extension that enables the use of ML Kit Text Recognition v2 API for offline text recognition.

Extension relies on Google Play Services to download the text recognition modules. Only Latin format is currently being supported by the extension.

🧩 Blocks


  • Returns true if Google Play Services are installed, they are required for the extension to work

  • Checks if the text recognition mododules are already installed on the device

    Modules Available

    • Modules are ready for use, only proceed when called

    • Modules are not present on the device and therefore needs to be downloaded

DownloadModules

  • Begins downloading text recognition modules

    • Download status was updated, possible states:
     unknown = 0, 
     pending = 1, 
     downloading = 2, 
     canceled = 3, 
     completed = 4, 
     failed = 5, 
     installing = 6,
     download_paused = 7 
    

    • Module installation was successful, text recognition is ready for use

    InstallationFailed

    • Installation was failed, there could be various reasons like Google Play Services or not installed on the device, or there was any interruption

ProcessFile

  • Takes in the image input from a file path

ProcessUri

  • Similarly, takes in the image input from Uri object or Uri

ProcessImageView

  • Retrieves the image resource from the Image component

  • Text recognition was successful
    • text is the total combined detected elements
    • blocks is a list of dictionaries, each dictionary contains:
      • text a text block
      • lines a list of lines
      • confidences list of confidence values corresponding to the lines
      • angles list of angles values corresponding to the lines

There will be more number of parameters added over time

GetImageOrientation

  • Get's the image file's EXIF orientation data, could be used with ProcessFile

Resources

Blocks

Also see: Input Image Guidelines

xyz.kumaraswamy.textrecognition.aix (270.6 KB)
TextRecognition2.aia (272.2 KB)

Extension is specially crafted with optimizations and to reduce redundancy :grin:

Thanks,
Kumaraswamy B G


MLKit Text Recognition Implementation © 2023 by Kumaraswamy B G is licensed under CC BY-ND 4.0

13 Likes

Hi Kumaraswamy,
I'm trying to use your extension by reading an image from a file but I get a runtime error.
This is my block


p.s. using filePicker with ProcecUri or setting rotation to 0, the same file is recognized perfectly
Thank you
Alex

1 Like

Companion on Android 13:

It should work fine in Apk. Does it?

1 Like

It's because apps can no more directly access the internal storage, maybe try with application specific directory instead.


You need to build the APK to be able to use the extension :slight_smile:

1 Like

Try to request READ_EXTERNAL_STORAGE and READ_MEDIA_IMAGES (on Android 13+) first.

Hi Kumaraswamy,
As I wrote in my previous message, the recognition works well when the rotation is set to 0. The problem lies in the usage of GetImageOrientation.
Could you please explain how it should be used with the ProcessFile function?
Thank
Alex

0 rotation will work fine in most of the cases.
So you should avoid using GetImageOrientation block.

In REAL applications the possibility to correct the rotation before recognition is VERY useful.
I hope that Kumaraswamy will be able to correct the problem with GetImageOrientation

Hi, can you please show me the problem you face while using GetImageOrientation?

Hi, the example in my first message is giving a `Runtine Error'.

Did you test it in the companion or compiled application?

Compiled. And substituting GetImageOrientation with 0 - the recognition works without any error

1 Like

I'll do some more research on it, I believed it worked fine, I'll revisit it once :slight_smile:

Thank you very much.
P.s. in current extension version the error is stable and you will see it immediately

1 Like

Version 1.1 :memo:

  • Adds full support for testing in the Companion Mode ( all features are available )

  • Fixes block ( Get Image Orientation ) where it returned unusable orientation data

  • Internal component optimizations

TextRecognition.aia (267.2 KB)
xyz.kumaraswamy.textrecognition.aix (265.5 KB)

@Alexandre_Gorine

5 Likes

It works perfectly! Thank you very much!

1 Like

Hello @Kumaraswamy, i have tested the extension, and i have 3 phones for test an app based in the extension.
I read the in the documentation of

and seems i need to have a android device of API 21 or superior.
I have no problem with that, because i have the 3 phones with api >to 23.
l have 1 with API 23, the other is API 26, and the last is Android 11.

The problem start with this message in the lower (API 23) phone.

The app start, and look ok with the companion but in the pc show this, and then when the recognition is done, i see this message in the phone.

Can you tell me what i am doing wrong.
Because the APi is ok, and in the other phones i have no problem at all.
I give you my thanks for any help you can provide.

Do you mean the extension works fine in the companion but not in the compiled APK?

Also are you trying to run this on an emulator in PC? I havent really tested running it on a PC before.

Hi. The problem is:

In the Android 6 doesn't work and in Android 8 and 11 works.
I do it with the companion.
When start with the companion - in the pc show this problem, and the same message appears in the phone (after take the photo and in the process of recognize the characters).
In this case, i do not make the apk, because stop working at the start.

In Android 8 and 11 works properly.
The documents say I need android 5 or superior. And as i say. I have android 6 and show me this error, related to core-libreart.jar