B4A Library Minimal Text OCR using Google Vision

[Copied from "Google Play Vision Services or Android Vision API wrapper" in "Bugs and wishlist" forum]

Hi again,

I found a solution by writing a wrapper library for my modified code written in Android Studio; thanks to tutorials and example code in this forum. This wrapper only performs text recognizing/scanning on an existing image file. It does not display anything.

BSTextOCRMin 1.0

Methods
  • Initialize(prmEventName As String)
  • Run(prmFileName As String)
    prmFileName should contains full file name, example value:
    B4X:
    fname = File.Combine(File.Combine(File.DirRootExternal, "Pictures"), "tmpscan.jpg")
Events
  • onSuccess(prmBlocks As String, prmLines As String, prmWords As String)
    They are the results in comma separated. Note: They may contain empty values.
  • onError(prmErrMsg As String)
  • onDone
Dependencies
B4X:
constraint-layout-1.0.1.aar
com.android.support:support-v4
com.android.support:appcompat-v7
com.android.support:design
com.google.android.gms:play-services-vision
Permisions
  • android.permission.READ_EXTERNAL_STORAGE
Installation
  • Extract "BSTextOCRMin.jar" and "BSTextOCRMin.xml" to B4A Additional Libraries folder.
  • Extract "add-res" onto project's folder.
Additional code
B4X:
#AdditionalRes: ..\add-res
#Extends: android.support.v7.app.AppCompatActivity
Put it below "#Region Activity Attributes".
"add-res" is a folder containing a few files required and the name might be changed to whatever you'd like. This folder should be placed in the same folder with "Files" and "Objects".

Recommended implementation
  • Call camera intent to get a picture file.
  • Enhance the picture (resize, sharpen, contrast, greyscale, or other) to expect better scan accuracy.
  • Scan the picture with this library and get result.
  • Optionally, delete the picture file after done.
I share this for B4A community to be used freely. Comments are welcomed. Thank you.


Cheers,
 

Attachments

  • BSTextOCRMin.zip
    50.2 KB · Views: 375

ruut

New Member
Licensed User
Longtime User
Hi Xenno,
It would be great if you could extend your code examples a bit. You wrote:
Methods
  • Initialize(prmEventName As String)
  • Run(prmFileName As String)
    prmFileName should contains full file name, example value:
    B4X:
    fname = File.Combine(File.Combine(File.DirRootExternal, "Pictures"), "tmpscan.jpg")

I am wondering how to feed the fname string into the BSTextOCRMin 1.0 object? What to use for prmEventName during the initialization phase.
 
Top