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

Johan Schoeman

Expert
Licensed User
Longtime User
I have just downloaded B4A V6.80 and it works without any problems.

I don't have such a folder structure in my B4A project....?
invalid resource directory name: C:\Program Files (x86)\Anywhere Software\Basic4android\Programs\b4aAndroidVisionOCR\Objects\bin\extra\res6\res/drawable-anydpi-v21
 

Attachments

  • 5.png
    319.8 KB · Views: 387

billmoultrie

Member
Licensed User
Longtime User


Thanks for your reply.
I created a new version of b4aAndroidVisionOCR and this is the file structure before compiling (Files1).
Then I compiled and got (Files2)


Have I put OCRres and resource in the wrong place.
As you can see drawable-anydpi-v21 is created.

I would be grateful if you could give me a clue as to what I am doing wrong.
 

Douglas Farias

Expert
Licensed User
Longtime User
@Johan Schoeman
Hi.
i m testing your lib, it works fine on my device, i can read big words etc..
but the auto focus dont is working, and my device have auto focus, i use auto focus in cam ex.

my device is a samsung galaxy j2

here on your lib really dont work the auto focus, can u fix this pls?
if it works i can send u a donation for u work, i will use your lib.

Obs: the focus seems to work, but only for long distances, I can not use it for closer distances

thx
 
Last edited:

Johan Schoeman

Expert
Licensed User
Longtime User
Try with the attached library files (V1.03). Have added the following options as far as focus is concerned:
B4X:
'Use one of the following:
'   FOCUS_MODE_CONTINUOUS_PICTURE
'   FOCUS_MODE_CONTINUOUS_VIDEO
'   FOCUS_MODE_AUTO
'   FOCUS_MODE_EDOF
'   FOCUS_MODE_FIXED
'   FOCUS_MODE_INFINITY
'   FOCUS_MODE_MACRO
    avocr.FocusMode = avocr.FOCUS_MODE_MACRO

I guess you are looking for FOCUS_MODE_MACRO....

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
   
    Private CheckBox1 As CheckBox
    Private CheckBox2 As CheckBox
    Private Label1 As Label
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
    avocr.OCRInfoMessage = "Toccare per acquisire. Pizzica/Stretch per lo zoom"         'used https://www.freetranslation.com/en/translate-english-italian for translation

    'Use one of the following:
'   FOCUS_MODE_CONTINUOUS_PICTURE
'   FOCUS_MODE_CONTINUOUS_VIDEO
'   FOCUS_MODE_AUTO
'   FOCUS_MODE_EDOF
'   FOCUS_MODE_FIXED
'   FOCUS_MODE_INFINITY
'   FOCUS_MODE_MACRO
    avocr.FocusMode = avocr.FOCUS_MODE_MACRO
   

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

Sub avocr_scanned_text(scannedText As String)
   
    Log("Scanned text = " & scannedText)
    Label1.Text = " " & scannedText
   
End Sub
 

Attachments

  • resource.zip
    423 bytes · Views: 601
  • b4aAndroidVisionOCR.zip
    9.5 KB · Views: 646
  • OCRres.zip
    30.7 KB · Views: 614
  • AndroidVisionOCR_libFilesV1.03.zip
    37.5 KB · Views: 648

Douglas Farias

Expert
Licensed User
Longtime User

hi Johan, many thx for your suport.

i tested all focus mode here.
' FOCUS_MODE_CONTINUOUS_PICTURE
' FOCUS_MODE_CONTINUOUS_VIDEO
' FOCUS_MODE_AUTO
' FOCUS_MODE_EDOF
' FOCUS_MODE_FIXED
' FOCUS_MODE_INFINITY
avocr.FocusMode = avocr.FOCUS_MODE_MACRO

the best for my device is the MODE_MACRO, all anothers dont FOCUS here.
but in mode macro have a problem.

He is focusing only if you approach the document very closely.

here is the result using FOCUS_MODE_MACRO (i need scan this document)




and here is FOCUS_MODE_MACRO Next to the document (with works next, but i need take all document Like the picture above)




Very close: has focus
Distant: no

its possible make a continuos focus for this lib?
on cam ex class in any distance the focus Self adjust

i found this subs on cam ex (maybe can help)
B4X:
Public Sub GetSupportedFocusModes As List
    r.target = parameters
    Return r.RunMethod("getSupportedFocusModes")
End Sub

Public Sub SetContinuousAutoFocus
    Dim modes As List = GetSupportedFocusModes
    If modes.IndexOf("continuous-picture") > -1 Then
        SetFocusMode("continuous-picture")
    Else If modes.IndexOf("continuous-video") > -1 Then
        SetFocusMode("continuous-video")
    End If
End Sub

Public Sub SetFocusMode(Mode As String)
    r.target = parameters
    r.RunMethod2("setFocusMode", Mode, "java.lang.String")
End Sub

Public Sub GetFocusDistances As Float()
    Dim F(3) As Float
    r.target = parameters
    r.RunMethod4("getFocusDistances", Array As Object(F), Array As String("[F"))
    Return F
End Sub

Public Sub GetSupportedPictureFormats As List
    r.target = parameters
    Return r.RunMethod("getSupportedPictureFormats")
End Sub

B4X:
        camEx.SetJpegQuality(100)
        camEx.SetContinuousAutoFocus
        camEx.CommitParameters
        camEx.StartPreview

the continuous focus is working very good on cam ex.
i think on your lib have only fixed modes

can u try add this pls?


another question.
its possible get all text of this document? And not only of a square touched
i need scan a document like the images, get all string possible and send via server.

thx again for u support
i really need this lib, if works ok, i send u 50$

i made a job offer about this, u lib is very next what i need
https://www.b4x.com/android/forum/threads/ocr-lib-to-b4a-real-time.77197/

thx
 

Johan Schoeman

Expert
Licensed User
Longtime User

Enjoy...
 

Johan Schoeman

Expert
Licensed User
Longtime User
hi @Johan Schoeman ,

any update for this? is it possible for grab/get all the text that already marked?
Hi Leni

Have not figured it out - but have spent very little time on this as I am too occupied by my actual work and other special requests. When I have some time I will look into it.

JS
 

wirog80

Member
Licensed User
thanks @Johan Schoeman for great library.

i want to use this lib as LPR (license plate recognition).
i have try a sample source/APK and it work successfully to detect a plate number.

maybe this is my idea/request for added
before start scan, can you set the camera on the one area/region to focused recognition,
so not recognition other text.
like this picture..



thanks for all
 

Eme Fibonacci

Well-Known Member
Licensed User
Longtime User
To use this library do I need to create an account to get an API key?
Is this a google online service with OCR?


Sorry if this question is wrong
 

Johan Schoeman

Expert
Licensed User
Longtime User
To use this library do I need to create an account to get an API key?
Is this a google online service with OCR?


Sorry if this question is wrong
No need to create an account or to get an API key. It just requires an initial Internet connection as it will download some dependencies. Once downloaded it will function without being connected to the Internet.
 

Eme Fibonacci

Well-Known Member
Licensed User
Longtime User
No need to create an account or to get an API key. It just requires an initial Internet connection as it will download some dependencies. Once downloaded it will function without being connected to the Internet.


Thanks for the answer.

This is amazing. I really need an OCR solution.

Google Cloud vision is very good however it is online and paid.
Https://cloud.google.com/vision/?hl=en-us

Can you tell if the results are as good as the online vision?
 

Johan Schoeman

Expert
Licensed User
Longtime User

Fabri

Member
Licensed User
if I add
#AdditionalRes: ..\resource
#AdditionalRes: ..\OCRres
to a subroutine, it give me this error:
Attribute not supported: additionalres

Running B4A version 6
Any idea?
TIA
 
Last edited:

imbault

Well-Known Member
Licensed User
Longtime User
Hi @Johan Schoeman, super work
It is possible to add the recognition of Barecodes and QR codes in your library (I can pay for that)

Thanks
 

Johan Schoeman

Expert
Licensed User
Longtime User
Cookies are required to use this site. You must accept them to continue using the site. Learn more…