B4A Library [B4X] TextRecognition based on MLKit

Not open for further replies.
This is a B4A + B4i solution. It recognizes text in images based on Google ML Kit.



- MediaChooser library: https://www.b4x.com/android/forum/t...ss-platform-videos-and-images-chooser.161093/
- B4i - iCPP: https://www.b4x.com/android/forum/threads/updates-to-internal-libraries.48179/post-989232
- B4i (local Mac only): https://www.b4x.com/b4i/files/MLKit.zip
- B4A: open B4A Sdk Manager - search for mlkit and install all items. Also search and install odml.

Don't miss:

- B4i dependencies + #PlistExtra (for MediaChooser) in Main module.
- B4i bundle files under Files\Special. The example includes bundles for Latin and Chinese. Other bundles are available here: https://www.b4x.com/b4i/files/MLKit_Bundles.zip
- B4A dependencies in Main module.
- B4A manifest editor. 2 snippets for MLKit and one snippet for FileProvider (MediaChooser).

Usage itself is very simple. See the example:


- v1.10:
Support for non-Latin languages added. There are 5 language models: Latin, Chinese, Devanagari, Japanese, Korean
Recognizing non-Latin languages requires some configuration:
  • Initialize the recognizer with the correct model.
  • B4A: add reference with #AdditionalJar: com.google.android.gms:play-services-mlkit-text-recognition-chinese (replace chinese with the relevant lowercased model name).
  • B4i: add the bundle of the relevant model: https://www.b4x.com/b4i/files/MLKit_Bundles.zip
Note that B4i MLKit package for local mac was updated as well as the #AdditionalLib list.
Last edited:


I used these codes in the B4A project, but it gives this error. It seems that it must be a cross-platform project. Thank you, can you fix this problem?




Licensed User
i do,but got error.this is my test:
my pc:windows11 21H2 22000.2538
Android emulator:android 7.1.2
my phone:harmonyOS 4.0.0

offline test result:
#AdditionalJar: com.google.mlkit:text-recognition
#AdditionalJar: kotlin-stdlib-1.6.10
#AdditionalJar: androidx.arch.core:core-runtime
'#AdditionalJar: com.google.mlkit:text-recognition-chinese  'error
'#AdditionalJar: com.google.mlkit:text-recognition-japanese  'error
'#AdditionalJar: com.google.mlkit:text-recognition-latin  'error
'#AdditionalJar: com.google.mlkit:text-recognition-devanagari  'error

'ok but ocr nothing  
#AdditionalJar: com.google.mlkit:text-recognition-korean

korean log in b4a ide: com.google.mlkit.common.MlKitException: Failed to run text recognizer text-recognition
Not open for further replies.