Android Tutorial [Example] Add OCR features to your Android application

Status
Not open for further replies.

GMan

Well-Known Member
Licensed User
Longtime User
Tested it, got the same error message.
If i uncommented the Log(...) part, the eroor message is another:

B4X:
B4A Version: 8.80
Parse den Code.    (0.04s)
Building folders structure.    (0.13s)
Kompiliere den Code.    (0.09s)
Kompiliere Layoutcode.    (0.01s)
Organisiere Libraries.    (0.00s)
Generiere R Datei.    (0.21s)
Kompiliere generierten Java Code.    Error
B4A line: 16
hc.Initialize(\
javac 1.8.0_66
src\b4a\example\httputils2service.java:208: error: cannot access ClientProtocolException
_hc.Initialize("hc");
              ^
  class file for org.apache.http.client.ClientProtocolException not found
 

GMan

Well-Known Member
Licensed User
Longtime User
I removed the HttpUtils2Service.bas and used the HttpUtils2 lib.

NOW the code compiles, but the App could not be installed on the device ;-)
 

GMan

Well-Known Member
Licensed User
Longtime User
Thougth it could have the reason in the "age" of the file (its from 2013 and many things have changed since them)
Added RuntimePermissions - no success
Removed the depreceated HttpUtil2 lib and chooses OKHttpUtils2 and removed the httpJob.bas - no success

Now i won't waste my time anymore with this - would be a nice solution to build some apps for business people, who often have these ugly bills to "store" FOR TAX etc.
Sun is shining here in DE, going for a short shopping trip to the netherlands now - just some minutes away
 

DonManfred

Expert
Licensed User
Longtime User

this example is based on Camera2 Example and some parts from the old example.

Basically it is this Code

B4X:
        Dim userbase64 As String = "USERNAME:code"
        Dim job As HttpJob
        job.Initialize("ocr", Me)
        job.PostBytes("https://www.ocrwebservice.com/restservices/processDocument?gettext=true&language=english,german", ReadFile(VideoFileDir, "1.jpg"))
        job.GetRequest.SetHeader("Authorization", "Basic "&su.EncodeBase64(userbase64.GetBytes("UTF8")))
        Wait For (j) JobDone(j As HttpJob)
        If j.Success Then
            'File.WriteString(File.DirRootExternal, "JobResult.txt", j.GetString)
            Log(j.GetString)
        Else
            Log(j.ErrorMessage)
        End If
        j.Release


This is the Picture i´ve taken


Have fun
 

Attachments

  • OCREx.zip
    16 KB · Views: 791

GMan

Well-Known Member
Licensed User
Longtime User
Works fine so far but:

The numbers and the text is recognized (as it looks), but has another issue

And an additional positive message:
Picture taken: (Bitmap): 1088 x 1920, scale = 1,00
 
Last edited:

Tadeu Botelho

Member
Licensed User
Longtime User
Thank you all for the help!
I came to the conclusion not to use this example because there are many bugs to be fixed.
Does anyone know of any professional API service available for B4A?
I would like to use a trust API for a very serious project in healthcare. I need an API that is not free. Because the free ones I've analyzed do not work correctly.
But I'm having trouble locating a service from some OCR company.
Hug to everyone.
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
I came to the conclusion not to use this example because there are many bugs to be fixed.
The issue you experienced is not a bug. This example was written when the old HttpUtils2 was the recommended way to make http requests. All that you need to do is to remove it and switch to OkHttpUtils2.

It is also possible that the 3rd party web service has changed since this example was written (in 2013). Start a new thread for any question you have.
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…