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

Discussion in 'Tutorials & Examples' started by Erel, Mar 7, 2013.

Thread Status:
Not open for further replies.
  1. Erel

    Erel Administrator Staff Member Licensed User

    This example demonstrates how you can use an OCR web service to recognize text in camera images.

    The program allows you to take a picture and then send it to OCRWebService.

    OCRWebService returns the recognized text in various formats. This is not a free service, however they offer a free trial and their prices are not high.

    Camera picture:

    [​IMG]

    Recognized html:

    [​IMG]

    While the response is not perfect, the text can still be extracted.

    The web service is a SOAP web service. The request is created by loading a template file and changing its fields. The response is then parsed and the data file is extracted.

    In order to run this example you need to create an account and enter your user name and license key.

    Updated example written by DonManfred: https://www.b4x.com/android/forum/t...-android-application.27080/page-2#post-656725
     
    Last edited: Apr 14, 2019
  2. susu

    susu Well-Known Member Licensed User

    Last edited: Mar 7, 2013
  3. laviniut

    laviniut Active Member Licensed User

    I tried OCR example with a trial account on OCRWebService. But the application is never focusing on camera and when send picture, application stopped with error main_buildrequest (java line: 337) and after is java.lang.OutOfMemoryError.
    I have Galaxy S2 and android 4.1.2
    Why is that ?
     
  4. Erel

    Erel Administrator Staff Member Licensed User

    You should decrease the picture size. You can change the size of the picture taken with CameraEx.SetPictureSize.
     
  5. laviniut

    laviniut Active Member Licensed User

    i use this <code
    Sub Camera1_Ready (Success As Boolean)
    If Success Then
    CamEx.SetContinuousAutoFocus
    CamEx.SetJpegQuality(90)
    CamEx.SetPictureSize(380, 480)
    CamEx.CommitParameters
    CamEx.StartPreview
    Else
    ToastMessageShow("Cannot open camera.", True)
    End If
    End Sub
    code/>
    but the same error.
    i think CameraExClass is not working good for me, because autofocus is not working, and the size of picture taken is same (maximum).
     
  6. Erel

    Erel Administrator Staff Member Licensed User

    Have you checked whether this picture size is supported? You should call GetSupportedPicturesSizes.

    You should download the latest CameraEx class for an auto-focus feature.
     
  7. laviniut

    laviniut Active Member Licensed User

    I updated CameraEx class. Thank you. Now autofocus is working. And yes, size i wanted for picture is not suported. So i have to set other size. But when i use Log(CamEx.GetSupportedPicturesSizes()) the result is [Lb4a.example.cameraexclass$_camerasize;@41240d80
    so, how can i get picture sizes ?
     
  8. laviniut

    laviniut Active Member Licensed User

    Now OCR example with my trial account is working.
    but CamEx.SetContinuousAutoFocus is not working. only CamEx.FocusAndTakePicture is working.
    i can set and get results with 800x480 picture size.
     
  9. Erel

    Erel Administrator Staff Member Licensed User

    You should write:
    Code:
    Dim l1 As List = CamEx.GetSupportedPicturesSizes
    You can then go over the items in the list.
     
  10. laviniut

    laviniut Active Member Licensed User

    Thank you. is working CamEx.GetSupportedPicturesSizes.
     
  11. XverhelstX

    XverhelstX Well-Known Member Licensed User

  12. Magics

    Magics Member Licensed User

    Hi,
    I followed this guide and i am registered on Ocrwebservice.com, but i can not figure out how to configure the application with my profile registered in ocrwebservice.com

    I found this code in the project source:

    Code:
    Sub BuildRequest (date () As Byte) As String
    Dim req As String = template
    req.Replace req = (
    "$ USER $", user)
    req.Replace req = (
    "$ $ LICENSE" license)
    req.Replace req = (
    "$ FILENAME $", tempfile)
    Dim about As StringUtils
    req.Replace req = (
    "$ DATE $", su.EncodeBase64 (date))
    req.Replace req = (
    "$ $ LANGUAGE""ENGLISH")
    req.Replace req = (
    "$ OUTPUT $""HTML")
    Return req
    end Sub

    The fields "eg: $ USER $ - $ LICENSE $" are to be filled?
    Iif the answer is yes.
    I could give an example, how do I compile it?

    Thanks in advance, Magics
     
  13. Erel

    Erel Administrator Staff Member Licensed User

    You should set the two global variables:
    Code:
    Private user = "ENTER USER", license = "LICENSE" As String
     
  14. Magics

    Magics Member Licensed User

    Thank you Erel, now I try and let you know!

    Magics
     
  15. sconlon

    sconlon Active Member Licensed User

    I have been trying this example and sending various pictures some with only a few words on them and each in perfect focus. Each time I get a Job successful but no text is displayed and I can see that the 1.XML document contains an error "Recognition failed". It also advises to contact support but before doing that I thought I would ask here in case someone might know what is going wrong. I have attached the latest picture I sent, it is 640x480.

    Thanks,
    SC
     

    Attached Files:

    • 1.jpg
      1.jpg
      File size:
      8.5 KB
      Views:
      468
  16. Erel

    Erel Administrator Staff Member Licensed User

    I no longer have an account with them so I cannot test it. Sorry.
     
  17. NJDude

    NJDude Expert Licensed User

    You can give THIS library a shot.
     
  18. sconlon

    sconlon Active Member Licensed User

    I contacted their support and got a reply back saying they no longer supported HTML as an output format. I changed it to TXT and it worked fine and the results were quite good.

    I will try NJDudes's library as well and see how it performs.

    Thanks.
     
  19. Tadeu Botelho

    Tadeu Botelho Member Licensed User

    I'm really in need of a professional OCR service on android.
    I'm having a problem trying to compile the APK to use the OCR service in this example.
    I did not change the sources. I just included my trial username and registration key to use the service.
    Can someone help me identify?
    Thank you
     

    Attached Files:

    • Err.PNG
      Err.PNG
      File size:
      76.6 KB
      Views:
      108
  20. GMan

    GMan Well-Known Member Licensed User

    The error message is clear: a class file was not found

    Try to uncomment the line (its only a log entry) and try again
     
Thread Status:
Not open for further replies.
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice