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

TextRecognition.aia (267.2 KB)
xyz.kumaraswamy.textrecognition.aix (265.5 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

10 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

3 Likes

It works perfectly! Thank you very much!

1 Like