B4A Library [B4X] TextRecognition based on MLKit

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




Dependencies:

- 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:

Updates:

- 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.gmslay-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:

benyamin

Member
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?

@Erel

 

byz

Active Member
Licensed User
i do,but got error.this is my test:
B4A:12.8
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
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…