This request comes from here:
https://www.b4x.com/android/forum/threads/ocr-offline-on-screen.84867/#post-538774
The attached project extracts text from a bitmap that you can pass to the library making use of the Android Vision API.
Sample code:
Take note of the B4A manifest file:
If you don't have the Android Vision dependencies installed then you will need an initial internet connection for the dependencies to be installed. After that an internet connection will not be required.
This is version 1.00. It will expire on 31 October 2017.
Bitmap loaded into the imageview.
B4A Log when clicking on button Read Text
https://www.b4x.com/android/forum/threads/ocr-offline-on-screen.84867/#post-538774
The attached project extracts text from a bitmap that you can pass to the library making use of the Android Vision API.
Sample code:
B4X:
#Region Project Attributes
#ApplicationLabel: b4aMobileVisionBitmap
#VersionCode: 1
#VersionName:
'SupportedOrientations possible values: unspecified, landscape or portrait.
#SupportedOrientations: portrait
#CanInstallToExternalStorage: False
#End Region
#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 mvbm As MobileVisionBitmap
Private Button1 As Button
Private iv1 As ImageView
Private bm As Bitmap
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")
bm.Initialize(File.DirAssets,"saying1.png") 'saying.png and saying1.png are in the /Files folder of the B4A project
iv1.Bitmap = bm
mvbm.Initialize("mvbm")
End Sub
Sub Activity_Resume
End Sub
Sub Activity_Pause (UserClosed As Boolean)
End Sub
Sub Button1_Click
mvbm.decodeBitmap(bm)
bm = Null
bm.Initialize(File.DirAssets,"saying1.png") 'saying.png and saying1.png are in the /Files folder of the B4A project
iv1.Bitmap = bm
End Sub
Sub mvbm_blocks_result(blocks As String)
Log("B4A Blocks = " & blocks)
End Sub
Sub mvbm_lines_result(lines As String)
Log("B4A Lines = " & lines)
End Sub
Sub mvbm_words_result(words As String)
Log("B4A Words = " & words)
End Sub
Sub mvbm_error_result(error As String)
Log("B4A ERROR = " & error)
End Sub
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.
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" />)
If you don't have the Android Vision dependencies installed then you will need an initial internet connection for the dependencies to be installed. After that an internet connection will not be required.
This is version 1.00. It will expire on 31 October 2017.
Bitmap loaded into the imageview.
B4A Log when clicking on button Read Text
Attachments
Last edited: