Android Question AndroidVisionOCR

Xfood

Expert
Licensed User
I am also interested in the library for ocr, I try this example, when I press the scan button I get this error

java.lang.NoClassDefFoundError: Failed resolution of: Landroid/support/v7/app/AppCompatActivity;

what should i set to avoid this error?


Thank you

1596623746151.png
 
Upvote 0

Johan Schoeman

Expert
Licensed User
Longtime User
Try with this (B4A project attached):

Copy the jar and xml to your additional libs folder
Extract folder resource and OCRCompleteRes from the attached zip files and copy the folder (with their contents) to be on the same folder level as the /Files folder of the B4A project.

Click on a highlighted box (once the scanner is active) to return the text (text returned will be displayed in the label below button Start Scan)

Remember to do:
Tools -> Jetifier
Tools -> Clean project
....then compile B4A project

B4X:
#Region  Project Attributes
    #ApplicationLabel: b4aOCRComplete
    #VersionCode: 1
    #VersionName:
    'SupportedOrientations possible values: unspecified, landscape or portrait.
    #SupportedOrientations: portrait
    #CanInstallToExternalStorage: False
    #MultiDex: True
#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
  
'    Dim myfont As Typeface
    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")
'    myfont = Typeface.LoadFromAssets("digital-7.ttf")
  
'    avocr.OCRtypeFace = myfont
  
    avocr.OCRtextColor = Colors.Red                                    'the color of the text while OCR takes place
    avocr.OCRtextSize = 35.0                                           'the size of the text while OCR take place
    avocr.OCRrectangleColor = Colors.Green
    avocr.OCRrectangleWidth = 2.0
    avocr.TTSActive = False                                            'TTS active or not
  

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_selected_text_result(result As String)
  
    Label1.Text = ""
    Label1.Text = result                           'handle the result text returned
  
  
End Sub
 

Attachments

  • OCRReaderComplete.xml
    3.1 KB · Views: 292
  • OCRReaderComplete.jar
    43.7 KB · Views: 321
  • resource.zip
    423 bytes · Views: 305
  • OCRCompleteRes.zip
    164.4 KB · Views: 311
  • b4aOCRComplete.zip
    20.1 KB · Views: 294
Last edited:
Upvote 0

Mrphone

Member
Try with this (B4A project attached):

Copy the jar and xml to your additional libs folder
Extract folder resource and OCRCompleteRes from the attached zip files and copy the folder (with their contents) to be on the same folder level as the /Files folder of the B4A project.

Click on a highlighted box (once the scanner is active) to return the text (text returned will be displayed in the label below button Start Scan)

Remember to do:
Tools -> Jetifier
Tools -> Clean project
....then compile B4A project

B4X:
#Region  Project Attributes
    #ApplicationLabel: b4aOCRComplete
    #VersionCode: 1
    #VersionName:
    'SupportedOrientations possible values: unspecified, landscape or portrait.
    #SupportedOrientations: portrait
    #CanInstallToExternalStorage: False
    #MultiDex: True
#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
 
'    Dim myfont As Typeface
    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")
'    myfont = Typeface.LoadFromAssets("digital-7.ttf")
 
'    avocr.OCRtypeFace = myfont
 
    avocr.OCRtextColor = Colors.Red                                    'the color of the text while OCR takes place
    avocr.OCRtextSize = 35.0                                           'the size of the text while OCR take place
    avocr.OCRrectangleColor = Colors.Green
    avocr.OCRrectangleWidth = 2.0
    avocr.TTSActive = False                                            'TTS active or not
 

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_selected_text_result(result As String)
 
    Label1.Text = ""
    Label1.Text = result                           'handle the result text returned
 
 
End Sub

Thanks very much @Johan Schoeman šŸŒ¹šŸŒ¹
 
Upvote 0

Xfood

Expert
Licensed User
i am doing some rehearsal, you can make sure that it reads all paragraphs.?
returns only the paragraph where I tap
 

Attachments

  • photo_2020-08-08_09-34-36.jpg
    photo_2020-08-08_09-34-36.jpg
    101.2 KB · Views: 200
Upvote 0

Johan Schoeman

Expert
Licensed User
Longtime User
i am doing some rehearsal, you can make sure that it reads all paragraphs.?
returns only the paragraph where I tap
Here you go...

 
Upvote 0

ninja3

New Member
Goodnight. I do all the steps and it gives me an error that I can't understand. If you can help me I would appreciate it.
java.lang.NoClassDefFoundError: Failed resolution of: Lcom/google/android/gms/samples/vision/ocrreader/OcrCaptureActivity;
 
Upvote 0
Top