B4A Library OCR - MobileVisionText

This is a "shortcut" wrap for this project. I have zipped the complete B4A project (and it includes the aar, jar, and xml files). Copy the aar, jar, and xml files to your additional library folder.

The zipped project is here:
https://drive.google.com/file/d/0B4g9tud5lvjgSHE3VFc0aEZjUHc/view?usp=sharing

Libraries enabled:
Libraries.png



Take note of the B4A 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="5" android:targetSdkVersion="22"/>
<supports-screens android:largeScreens="true"
    android:normalScreens="true"
    android:smallScreens="true"
    android:anyDensity="true"/>)
SetApplicationAttribute(android:icon, "@drawable/icon")
SetApplicationAttribute(android:label, "$LABEL$")
'End of default text.

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.truiton.mobile.vision.ocr.MainActivity">

        </activity>)

Take note of the "resource" and "DemoRes" folders and contents that are on the same folder level as that of the B4A project's /Files and /Objects folders

What does this project do?
1. It starts the native camera
2. Take a photo of text
3. Save or discard the photo taken that has the text
3. If (3) = Save it returns the Blocks, Lines, and Words identified in the picture to the B4A project via events else it starts the camera again for you to take another photo of text.


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

#AdditionalRes: ..\DemoRes
#AdditionalRes: ..\resource


#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.

    Dim mvt As MobileVisionText

    Private Button1 As Button
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")

    mvt.Initialize("mvt")

End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub


Sub Button1_Click

    mvt.startMobileVisionText

End Sub

Sub mvt_blocks_result(blocks As String)

    Log("B4A Blocks = " & blocks)

End Sub

Sub mvt_lines_result(lines As String)

    Log("B4A Lines = " & lines)

End Sub

Sub mvt_words_result(words As String)

    Log("B4A Words = " & words)

End Sub

Sub mvt_error_result(error As String)

    Log("B4A ERROR = " & error)

End Sub

Have done this with B4A V6.80 and on a KitKat device.

Library:
MobileVisionText
Version:
1
MobileVisionText
Events:

  • blocks_result (blocks As String)
  • error_result (error As String)
  • lines_result (lines As String)
  • words_result (words As String)
Methods:
  • Initialize (paramString As String)
  • IsInitialized As Boolean
  • startMobileVisionText
Permissions:
  • android.permission.CAMERA
  • android.permission.WRITE_EXTERNAL_STORAGE

To compile the Java code setup:
1. Create a libs folder on the same level as that of the src folder
2. Copy android-support-v4.jar, android-support-v7-appcompat.jar, constraint-layout-1.0.1.jar, and play-services-vision-9.4.0.jar into the libs folder that you have created.
 

Attachments

  • TheJavaCode.zip
    5 KB · Views: 667
Last edited:

mczubel

Member
Licensed User
Longtime User
Hi, Sorry but I can't see logs now, i have this result in logs:
** Activity (main) Create, isFirst = false **
** Activity (main) Resume **
** Activity (main) Pause, UserClosed = false **
sending message to waiting queue (OnActivityResult)
running waiting messages (1)
** Activity (main) Resume **
 

Ran Espensen

Member
Licensed User
Longtime User
Running on Samson phone , no problem but Samsug GT8000 tablet, se below

AppCompat' is not used.(warning#32)

Logger connected to: samsung GT-N8000
--------- beginning of /dev/log/main
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
** Activity (main) Pause, UserClosed = false **
java.lang.RuntimeException: Unable to start activity ComponentInfo{JHS.MobileVisionText/com.truiton.mobile.vision.ocr.MainActivity}: android.content.res.Resources$NotFoundException: File res/drawable/abc_vector_test.xml from drawable resource ID #0x7f020052
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2413)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2471)
at android.app.ActivityThread.access$900(ActivityThread.java:175)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1308)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:146)
at android.app.ActivityThread.main(ActivityThread.java:5603)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1283)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1099)
 

DonManfred

Expert
Licensed User
Longtime User
android.content.res.Resources$NotFoundException: File res/drawable/abc_vector_test.xml
vector-drawables are added in Android 6 (or so). Which android version does the GT-N8000 have?

You can try to use a higher Android.jar than you do now... Set it to platforms-26/android.jar
 

Johan Schoeman

Expert
Licensed User
Longtime User
Tanks
Version is 4.4.2
I try platform26
See my comment in post #1. I have done the project with B4A V6.80 and with a KitKat device (Samsung S4 mini). And I think I am using Android 25
 

DonManfred

Expert
Licensed User
Longtime User
Do you have the AppCompat.aar file in your additional library folder?
As he can compile i expect he has it there. But maybe a old version. 3.52 is the newest.
If he would not have it then he would get a note about a missing library (ApCompat)...
 

Ran Espensen

Member
Licensed User
Longtime User
Yes i have
AppCompat.jar , xml, aar dont know version ?
But i get log:
Library 'AppCompat' is not used.(Warning #39)
 

Johan Schoeman

Expert
Licensed User
Longtime User
Sorry AppCompat Version = 3.52
If you don't enable the AppCompat library (V3.52) you will get this error when you start the app:
java.lang.RuntimeException: Unable to start activity ComponentInfo{JHS.MobileVisionText/com.truiton.mobile.vision.ocr.MainActivity}: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.

So, the AppCompat library must be selected in the B4A Libs tab.
 

mczubel

Member
Licensed User
Longtime User
Excuse me, it's a basic question, but I can't escape this:
I can't see logs now, i have this result in logs:
** Activity (main) Create, isFirst = false **
** Activity (main) Resume **
** Activity (main) Pause, UserClosed = false **
sending message to waiting queue (OnActivityResult)
running waiting messages (1)
** Activity (main) Resume **
Work perfect first time............
 

Johan Schoeman

Expert
Licensed User
Longtime User
Excuse me, it's a basic question, but I can't escape this:
I can't see logs now, i have this result in logs:
** Activity (main) Create, isFirst = false **
** Activity (main) Resume **
** Activity (main) Pause, UserClosed = false **
sending message to waiting queue (OnActivityResult)
running waiting messages (1)
** Activity (main) Resume **
Work perfect first time............
Did it allow you the option to Save or Discard the photo after you have taken it?
 

Johan Schoeman

Expert
Licensed User
Longtime User

mczubel

Member
Licensed User
Longtime User
Top