B4A Library OCR - Optical Character Recognition with Google Play Services (Android Vision)

This is a wrap for this Github project. It is a SUPER OCR (Optical Character Recognition) app. I have even managed to read motor car number plates with it! Posting the following:
1. B4A sample project (it will only work with B4A V6.00)
2. B4A library files
3. resource.zip - extract it and copy the resource folder to be on the same folder level as that of the /Files and /Objects folders of the B4A project
4. OCRres.zip - extract it and copy the OCRres folder to be on the same folder level as that of the /Files and /Objects folders of the B4A project

You need to have the Google Repository installed (via the SDK manager). I have Google Repository V32 installed.

I am using this on a Samsung S4 mini with KitKat.

This is the libraries that I have enabled in my B4A project:

libsenabled.png


You will need the following jars in your additional library folder:
android-support-design.jar
android-support-v4.jar
android-support-v7-appcompat.jar
android-support-annotations.jar

You will also need the following libraries by @corwin42 (download from the forum):
AppCompat V3.20 - https://www.b4x.com/android/forum/t...compatible-with-older-android-versions.48423/
DesignSupport V2.00 - https://www.b4x.com/android/forum/threads/designsupport-additional-material-design-components.58893/

startb4a.png


startocr.png


Click on Detect Text to start the OCR (you can set the flash mode as well as autofocus).


1.png


Touch any of the highlighted blocks of text - I have clicked on the big block:

2.png


Just another sample of the OCR capability:

3.png


Can do some mods to bring back info to the B4A project via an event from the library....

Sample Code:
B4X:
#Region  Project Attributes
    #ApplicationLabel: b4aAndroidVisionOCR
    #VersionCode: 1
    #VersionName:
    'SupportedOrientations possible values: unspecified, landscape or portrait.
    #SupportedOrientations: portrait
    #CanInstallToExternalStorage: False
#End Region

#AdditionalRes: ..\resource
#AdditionalRes: ..\OCRres


'#AdditionalRes: C:\Users\----------2\Documents\Basic 4 Android\JOHAN APPS\JHS LIBS\resource\b4a_appcompat, de.amberhome.objects.appcompat
'#AdditionalRes: C:\ANDRIOD_SDK_TOOLS\extras\android\support\v7\appcompat\res, android.support.v7.appcompat
'#AdditionalRes: C:\ANDRIOD_SDK_TOOLS\extras\google\google-play-services\libproject\google-play-services_lib\res, com.google.android.gms
'#AdditionalRes: C:\ANDRIOD_SDK_TOOLS\extras\android\support\design\res, android.support.design

'#ExcludeClasses: .games, .drive, .ads, .fitness, .wearable, .measurement, .cast, .auth, .nearby
'#ExcludeClasses: .tagmanager, .analytics, .wallet, .plus, .gcm, .maps, .panorama

'#Extends: android.support.v7.app.AppCompatActivity

#Region  Activity Attributes
    #FullScreen: False
    #IncludeTitle: True
#End Region

Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.



End Sub

Sub Globals
    'These global variables will be redeclared each time the activity is created.
    'These variables can only be accessed from this module.

    Private Button1 As Button
    Dim avocr As AndroidVisionOCR


End Sub

Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:

    Activity.LoadLayout("main")
    avocr.Initialize("")

    avocr.OCRtextColor = Colors.Yellow
    avocr.OCRtextSize = 30.0


End Sub

Sub Activity_Resume



End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

Sub Button1_Click

avocr.StartCameraFilter

End Sub

Library as it is at present:
AndroidVisionOCR
Author:
Github: Benjamin Johns, Wrapped by: Johan Schoeman
Version: 1
  • AndroidVisionOCR
    Fields:
    • OCRtextColor As Int
    • OCRtextSize As Float
    Methods:
    • Initialize (paramString As String)
    • IsInitialized As Boolean
    • StartCameraFilter
    Permissions:
    • android.permission.CAMERA

Take note of the B4A manifest Files:
B4X:
'This code will be applied to the manifest file during compilation.
'You do not need to modify it in most cases.
'See this link for for more information: https://www.b4x.com/forum/showthread.php?p=78136
AddManifestText(
<uses-sdk android:minSdkVersion="19" android:targetSdkVersion="23"/>
<supports-screens android:largeScreens="true"
    android:normalScreens="true"
    android:smallScreens="true"
    android:anyDensity="true"/>)
SetApplicationAttribute(android:icon, "@drawable/icon")
SetApplicationAttribute(android:label, "$LABEL$")
SetApplicationAttribute(android:theme, "@style/MyAppTheme")
AddApplicationText(<meta-data
            android:name="com.google.android.gms.version"
            android:value="@integer/google_play_services_version" />

<meta-data
            android:name="com.google.android.gms.vision.DEPENDENCIES"
            android:value="ocr" />

        <activity
            android:name="com.google.android.gms.samples.vision.ocrreader.MainActivity"
            android:label="@string/title_activity_main" >

        </activity>

        <activity android:name="com.google.android.gms.samples.vision.ocrreader.OcrCaptureActivity"
            android:label="Read Text" />)
AddPermission(android.permission.CAMERA) ' Required to be able to access the camera device.   
AddPermission(android.permission.GET_TASKS)
AddPermission("android.hardware.camera")
AddPermission("android.permission.FLASHLIGHT")
 

Attachments

  • b4aAndroidVisionOCR.zip
    8.7 KB · Views: 1,423
  • AndroidVisionOCRLibFiles.zip
    37.2 KB · Views: 1,358
  • resource.zip
    423 bytes · Views: 1,379
  • OCRres.zip
    30.7 KB · Views: 1,353
Last edited:

Cableguy

Expert
Licensed User
Longtime User
This is Icr no Ocr
I beg to disagree... Icr is used mostly in intelligent translation software in order to establish the origin language... This lib, is a combination of the two at best, although I don't think it can establish the "scanned" text language...
Ocr will just do that, recognise each individual character, machine type or handwritten (as long as legible), which this lib seems to do.
 

MarcoRome

Expert
Licensed User
Longtime User
I beg to disagree... Icr is used mostly in intelligent translation software in order to establish the origin language... This lib, is a combination of the two at best, although I don't think it can establish the "scanned" text language...
Ocr will just do that, recognise each individual character, machine type or handwritten (as long as legible), which this lib seems to do.
Maybe i wrong ... but look THIS LINK :

The difference between ICR and OCR
It is important to understand the distinction between different types of text recognition software. The well-known software is OCR, or optical character recognition. An OCR product is designed for use with printed text, and is frequently used for books and printed documents. ICR, short for intelligent character recognition, is used to recognize structured handwritten text. Because handwriting has more variation than printed text, ICR uses different algorithms.

Again look another LINK

The Main Difference Between OCR and ICR
While ICR is a subset of OCR software, the main difference is that OCR is generally not set up to recognize handwriting. It’s generally used to take paper documents that have been typed and turned into text so it can be searched and categorized. OCR text can also be copied and pasted. On the other hand, ICR focuses specifically on handwriting or printed materials that use more complicated fonts than OCRs can handle.

And in final this LINK

Optical Character Recognition (OCR) Software

OCR Software takes images, and converts them to searchable text. The output can be a plain text file, or the industry standard today is an image with hidden text PDF. OCR can also be utilized to extract data from scanned images, providing a means to either harvest information, or create index fields for later search. OCR Software Definition

Intelligent Character Recognition (ICR) Software

ICR Software provides the ability to recognize handwritten, or hand printed text. This process can be extrememly accurate when the printed text is bound by boxes, or combed form fields. Hanwriting is a little more complex, and typically requires many samples to be accurate. ICR Software Definition

Anyway isnt important... bye
 
Last edited:

PABLO2013

Well-Known Member
Licensed User
Longtime User
Sorry i have this problem .... many tks
 

Attachments

  • compiling.JPG
    compiling.JPG
    13.8 KB · Views: 270

PABLO2013

Well-Known Member
Licensed User
Longtime User
tks i solve it :
<uses-sdk android:minSdkVersion="14" android:targetSdkVersion="23"/>
 

Leni Berry

Active Member
Licensed User
Longtime User
Hi,

can this lib grab all capture text that already mark, not only choosen text (i click)
 

Johan Schoeman

Expert
Licensed User
Longtime User
Hi,

can this lib grab all capture text that already mark, not only choosen text (i click)

Leni, I will have to look into the original Java code and see if I can bring back all the highlighted text. Maybe sometime this coming weekend.
 

Johan Schoeman

Expert
Licensed User
Longtime User
Hi Johan, Great work! Can it also OCR full page A4 texts? If yes, how fast is it on average (in seconds)?
Will it do multi-column (magazine) pages (with or without pictures in between), with automatic column recognition?
Syd, not as the original github project stands at present. I think it will need some serious surgery to get that done
 

roberto64

Active Member
Licensed User
Longtime User
hi johan, compiler I ristituisce this error as in the image.
regards
 

Attachments

  • Compileimg.png
    Compileimg.png
    20.7 KB · Views: 239

Johan Schoeman

Expert
Licensed User
Longtime User
hi johan, compiler I ristituisce this error as in the image.
regards
Seems like you are missing the Google play services library that contains the required class or that you don't have it in your additional library folder.....
 

Johan Schoeman

Expert
Licensed User
Longtime User
hi johan, compiler I ristituisce this error as in the image.
regards
This is what I posted in post #1 of this thread
You need to have the Google Repository installed (via the SDK manager). I have Google Repository V32 installed.
 

roberto64

Active Member
Licensed User
Longtime User
HI, as provided in the image that you see and installed Google Repository v44, v39 Gogle Play services, and AdditionalLibs I inserted inside android-support-design.jar
android-support-v4.jar
android-support-v7-appcompat.jar
android-support-annotations.jar
regards
 

Attachments

  • Immagine.png
    Immagine.png
    67.1 KB · Views: 227
  • Immagine1.png
    Immagine1.png
    31.5 KB · Views: 217

roberto64

Active Member
Licensed User
Longtime User
HI, I do not understand why the direttre you use examples "'# AdditionalRes: C: \ ANDRIOD_SDK_TOOLS \ extras \ google \ google-play-services \ libproject \ google-play-services_lib \ res, com.google.android.gms" and diveso than that of Android as fuck attached.
regards
 

Attachments

  • Immagine2.png
    Immagine2.png
    33 KB · Views: 212

Johan Schoeman

Expert
Licensed User
Longtime User
HI, I do not understand why the direttre you use examples "'# AdditionalRes: C: \ ANDRIOD_SDK_TOOLS \ extras \ google \ google-play-services \ libproject \ google-play-services_lib \ res, com.google.android.gms" and diveso than that of Android as fuck attached.
regards
Roberto, I am not following whatever it is you are trying to tell me in your two posts above. Did you get it working or not?
 

roberto64

Active Member
Licensed User
Longtime User
Johan,
always the same error see image
regards
 

Attachments

  • Immagine3.png
    Immagine3.png
    38.3 KB · Views: 231

Johan Schoeman

Expert
Licensed User
Longtime User
Top