B4A Library OCR - OCR Reader Complete

A wrap for this Github project. Touch a green box with yellow text when the scanner is active and it will speak out the text in the box (using the Android Text-To-Speech Engine).

You need B4A V6.00 to run this project.

Change the Java code to your liking. Read the postings in this thread - it will give the a very good idea of how to set up this project.

1.png


Posting the following:
1. B4A library files - copy then to your additional library folder
2. B4A sample project
3. The Java code
4. OCRCompleteRes.zip - extract it and copy the folder to be on the same folder level as that of the /Files and /Objects folders of the B4A project
5. resource.zip - extract it and copy the folder to be on the same folder level as that of the /Files and /Objects folders of the B4A project
6. The .apk file generated by the B4A project is here should you want to test it - https://www.dropbox.com/s/jio7fc29ezclqxq/b4aOCRComplete.apk?dl=0
7. This is the link to Other library files (jars) that you either need in your additional library folder or in the libs folder of the library folder structure to compile the Java code - click on the red text to download.


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/

Take note of the b4A project manifest file:
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.OcrCaptureActivity"
            android:label="Wrapped by Johan Schoeman">
        </activity>) 
     
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")

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

#AdditionalRes: ..\resource
#AdditionalRes: ..\OCRCompleteRes


'#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 OCRReaderComplete
 
    Private CheckBox1 As CheckBox
    Private CheckBox2 As CheckBox
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")
 
    avocr.OCRtextColor = Colors.Yellow                                    'the color of the text while OCR takes place
    avocr.OCRtextSize = 30.0                                              'the size of the text while OCR take place
    avocr.OCRrectangleColor = Colors.Green
    avocr.OCRrectangleWidth = 2.0
 

End Sub

Sub Activity_Resume
 

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

Sub Button1_Click

    If CheckBox1.Checked = True Then
      avocr.UseFlash = True
    Else
      avocr.UseFlash = False 
    End If 

    If CheckBox2.Checked = True Then
      avocr.UseAutoFocus = True
    Else
      avocr.UseAutoFocus = False     
    End If

    avocr.StartOCRReader

End Sub

Library as it is at present:
OCRReaderComplete
Author:
Github: Benjamin Johns, Wrapped by: Johan Schoeman
Version: 1
  • OCRReaderComplete
    Fields:
    • OCRrectangleColor As Int
    • OCRrectangleWidth As Float
    • OCRtextColor As Int
    • OCRtextSize As Float
    Methods:
    • Initialize (paramString As String)
    • IsInitialized As Boolean
    • StartOCRReader
    Permissions:
    • android.permission.CAMERA
    Properties:
    • UseAutoFocus As Boolean [write only]
    • UseFlash As Boolean [write only]
 

Attachments

  • b4aOCRComplete.zip
    9 KB · Views: 880
  • OCRCompleteRes.zip
    30.9 KB · Views: 827
  • resource.zip
    423 bytes · Views: 798
  • OCRReaderCompleteLibFiles.zip
    36.6 KB · Views: 831
  • TheJavaCode.zip
    28.5 KB · Views: 741
Last edited:

Johan Schoeman

Expert
Licensed User
Longtime User

hears

Active Member
Licensed User
Longtime User
when compiling i get this erro,
maybe because i use DesignSupportLib2_31.zip ? here cannot find DesignSupportLib2.00,who can share it ?
https://www.b4x.com/android/forum/threads/designsupport-additional-material-design-components.58893/

B4X:
B4A Version: 7.30
Parsing code.    (0.00s)
Compiling code.    (0.05s)
Compiling layouts code.    (0.00s)
Organizing libraries.    (0.00s)
Generating R file.    Error
C:\Users\wu\Downloads\b4aOCRComplete\Objects\bin\extra\res6\res\values-v24\values-v24.xml:3: error: Error retrieving parent for item: No resource found that matches the given name 'android:TextAppearance.Material.Widget.Button.Borderless.Colored'.
C:\Users\wu\Downloads\b4aOCRComplete\Objects\bin\extra\res6\res\values-v24\values-v24.xml:4: error: Error retrieving parent for item: No resource found that matches the given name 'android:TextAppearance.Material.Widget.Button.Colored'.
 

Johan Schoeman

Expert
Licensed User
Longtime User
when compiling i get this erro,
maybe because i use DesignSupportLib2_31.zip ? here cannot find DesignSupportLib2.00,who can share it ?
https://www.b4x.com/android/forum/threads/designsupport-additional-material-design-components.58893/

B4X:
B4A Version: 7.30
Parsing code.    (0.00s)
Compiling code.    (0.05s)
Compiling layouts code.    (0.00s)
Organizing libraries.    (0.00s)
Generating R file.    Error
C:\Users\wu\Downloads\b4aOCRComplete\Objects\bin\extra\res6\res\values-v24\values-v24.xml:3: error: Error retrieving parent for item: No resource found that matches the given name 'android:TextAppearance.Material.Widget.Button.Borderless.Colored'.
C:\Users\wu\Downloads\b4aOCRComplete\Objects\bin\extra\res6\res\values-v24\values-v24.xml:4: error: Error retrieving parent for item: No resource found that matches the given name 'android:TextAppearance.Material.Widget.Button.Colored'.

I will revisit the lib and update it to accommodate the newer versions of B4A. This lib was done some time ago (Sept 2016) with an older version of B4A.
 

hears

Active Member
Licensed User
Longtime User
it is working now.after i change my Android.jar from 23 to 25.

maybe because i donot have Android.jar 24.

this lib need google play service.if no need google play will be better.

because many device donot have google play
 

Johan Schoeman

Expert
Licensed User
Longtime User
it is working now.after i change my Android.jar from 23 to 25.

maybe because i donot have Android.jar 24.

this lib need google play service.if no need google play will be better.
it depends on Google play services. Won't work without it. It initially needs to download the play services dependencies but once downloaded and installed an Internet connection is no longer required in order for it to work.
 

hears

Active Member
Licensed User
Longtime User
it depends on Google play services. Won't work without it. It initially needs to download the play services dependencies but once downloaded and installed an Internet connection is no longer required in order for it to work.
thank you
 

Kope

Active Member
Licensed User
Hi, if I have a lot of content but I want to scan only specific part (ie Only Numbers) eg. Scan credit card number but not the name, how can i filter?
 

fbritop

Active Member
Licensed User
Longtime User
HI @Johan Schoeman
I installed today your library (which is the only one I have found to work offline). It works just like your compiled APK. Did you ever added events to your library? onScanRead or something?

Thanks
FBP
 

JOTHA

Well-Known Member
Licensed User
Longtime User
Hello Johan,
I tried your code, but I got this Log-file:
Logger verbunden mit: samsung SM-A037G
--------- beginning of main
--------- beginning of system
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
main_activity_create (java line: 354)
java.lang.NoClassDefFoundError: Failed resolution of: Lcom/google/android/gms/samples/vision/ocrreader/OcrCaptureActivity;
at ocrreadercompletewrapper.ocrreadercompleteWrapper.Initialize(ocrreadercompleteWrapper.java:95)
at JHS.OCRComplete.main._activity_create(main.java:354)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:213)
at JHS.OCRComplete.main.afterFirstLayout(main.java:105)
at JHS.OCRComplete.main.access$000(main.java:17)
at JHS.OCRComplete.main$WaitForLayout.run(main.java:83)
at android.os.Handler.handleCallback(Handler.java:938)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:246)
at android.app.ActivityThread.main(ActivityThread.java:8633)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:602)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1130)
Caused by: java.lang.ClassNotFoundException: com.google.android.gms.samples.vision.ocrreader.OcrCaptureActivity
... 14 more
--------- beginning of crash
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
main_activity_create (java line: 354)
java.lang.NoClassDefFoundError: Failed resolution of: Lcom/google/android/gms/samples/vision/ocrreader/OcrCaptureActivity;
at ocrreadercompletewrapper.ocrreadercompleteWrapper.Initialize(ocrreadercompleteWrapper.java:95)
at JHS.OCRComplete.main._activity_create(main.java:354)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:213)
at JHS.OCRComplete.main.afterFirstLayout(main.java:105)
at JHS.OCRComplete.main.access$000(main.java:17)
at JHS.OCRComplete.main$WaitForLayout.run(main.java:83)
at android.os.Handler.handleCallback(Handler.java:938)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:246)
at android.app.ActivityThread.main(ActivityThread.java:8633)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:602)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1130)
Caused by: java.lang.ClassNotFoundException: com.google.android.gms.samples.vision.ocrreader.OcrCaptureActivity
... 14 more
Copying updated assets files (1)
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
java.lang.NoClassDefFoundError: Failed resolution of: Lcom/google/android/gms/samples/vision/ocrreader/OcrCaptureActivity;
at ocrreadercompletewrapper.ocrreadercompleteWrapper.Initialize(ocrreadercompleteWrapper.java:95)
at JHS.OCRComplete.main._activity_create(main.java:396)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:732)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:351)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:144)
at JHS.OCRComplete.main.afterFirstLayout(main.java:105)
at JHS.OCRComplete.main.access$000(main.java:17)
at JHS.OCRComplete.main$WaitForLayout.run(main.java:83)
at android.os.Handler.handleCallback(Handler.java:938)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:246)
at android.app.ActivityThread.main(ActivityThread.java:8633)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:602)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1130)
Caused by: java.lang.ClassNotFoundException: com.google.android.gms.samples.vision.ocrreader.OcrCaptureActivity
... 18 more
** Activity (main) Resume **
** Activity (main) Pause, UserClosed = true **
** Service (starter) Destroy (ignored)**
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
java.lang.NoClassDefFoundError: Failed resolution of: Lcom/google/android/gms/samples/vision/ocrreader/OcrCaptureActivity;
at ocrreadercompletewrapper.ocrreadercompleteWrapper.Initialize(ocrreadercompleteWrapper.java:95)
at JHS.OCRComplete.main._activity_create(main.java:396)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:732)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:351)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:144)
at JHS.OCRComplete.main.afterFirstLayout(main.java:105)
at JHS.OCRComplete.main.access$000(main.java:17)
at JHS.OCRComplete.main$WaitForLayout.run(main.java:83)
at android.os.Handler.handleCallback(Handler.java:938)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:246)
at android.app.ActivityThread.main(ActivityThread.java:8633)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:602)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1130)
Caused by: java.lang.ClassNotFoundException: com.google.android.gms.samples.vision.ocrreader.OcrCaptureActivity
... 18 more
** Activity (main) Resume **
** Activity (main) Pause, UserClosed = true **
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
java.lang.NoClassDefFoundError: Failed resolution of: Lcom/google/android/gms/samples/vision/ocrreader/OcrCaptureActivity;
at ocrreadercompletewrapper.ocrreadercompleteWrapper.Initialize(ocrreadercompleteWrapper.java:95)
at JHS.OCRComplete.main._activity_create(main.java:396)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:732)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:351)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:144)
at JHS.OCRComplete.main.afterFirstLayout(main.java:105)
at JHS.OCRComplete.main.access$000(main.java:17)
at JHS.OCRComplete.main$WaitForLayout.run(main.java:83)
at android.os.Handler.handleCallback(Handler.java:938)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:246)
at android.app.ActivityThread.main(ActivityThread.java:8633)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:602)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1130)
Caused by: java.lang.ClassNotFoundException: com.google.android.gms.samples.vision.ocrreader.OcrCaptureActivity
... 18 more
** Activity (main) Resume **
 

Johan Schoeman

Expert
Licensed User
Longtime User
Try this one...

 
Top