B4A Library TextRecognitionAndroid - OCR

simone77gl

Member
Licensed User
problem compilation:

Generazione file R. Error
c:\android\tools\..\extras\b4a_remote\androidx\savedstate\savedstate\1.1.0\unpacked-savedstate-1.1.0\res\values\values.xml:3: error: Found tag id where item is expected
c:\android\tools\..\extras\b4a_remote\androidx\lifecycle\lifecycle-viewmodel\2.3.1\unpacked-lifecycle-viewmodel-2.3.1\res\values\values.xml:3: error: Found tag id where item is expected
c:\android\tools\..\extras\b4a_remote\androidx\lifecycle\lifecycle-runtime\2.3.1\unpacked-lifecycle-runtime-2.3.1\res\values\values.xml:3: error: Found tag id where item is expected
 

ilan

Expert
Licensed User
Longtime User
Thank you very much @Johan Schoeman.
this is the first OCR lib that really worked for me (after so many tries)

i have tried the example from post#14

One question please. can we scan text from bitmap instead of the live camera?

thank you
 

Johan Schoeman

Expert
Licensed User
Longtime User
Thank you very much @Johan Schoeman.
this is the first OCR lib that really worked for me (after so many tries)

i have tried the example from post#14

One question please. can we scan text from bitmap instead of the live camera?

thank you
 

ilan

Expert
Licensed User
Longtime User

adriano.freitas

Active Member
Hi!

Very good job! Congratulations!

I just have one question: I would like to use it as a function for a specific part of my application. A panel that is displayed or hidden as needed. For the sake of use of device resources, I think that the ideal would be to turn on the camera when displaying the panel to do the OCR and after reading the text, turn off the camera when hiding the panel, preventing the system from having resources used unnecessarily.

How can I do this?
 

adriano.freitas

Active Member
Another thing I noticed when inserting the library into my application is that it takes two "startscans" for the preview to be functional. Why?

Thanks
 

Johan Schoeman

Expert
Licensed User
Longtime User
Another thing I noticed when inserting the library into my application is that it takes two "startscans" for the preview to be functional. Why?

Thanks
Does the original sample code behave this way or just when you use it in your project?
 

adriano.freitas

Active Member
Hi!

In this case, it happened in my application, because in it, unlike the example, I shouldn't leave the camera on all the time. Thus, when reading a text, I need the camera to be turned off (I use stopscan, followed by visible false) and the user can turn it on again on a button (I use start scan and visible=true). So, after disabling the camera once, I need to double-tap the enable button so that it actually becomes active again.

I must emphasize that I capture the text via a button as well and not by tapping the image (according to an update posted at the request of someone else).
 

Johan Schoeman

Expert
Licensed User
Longtime User
Probably best that you upload a sample project that illustrates what it is that you are seeing.
 

adriano.freitas

Active Member
Probably best that you upload a sample project that illustrates what it is that you are seeing.

Hi!

The whole project I think will be more confusing because it's a big application, with a lot of code and it wouldn't be relevant, so I'm going to copy here the parts of the code that refer to OCR, ok? My natural language is Portuguese, so some variable names and the like may be in this language.

Basically it's the code below. Just what I talked about before, it already happens:


B4X:
Private Sub OCRCamera_Click
	'
	'  Sub to start OCR by activating the camera
	'
       OCRTextoEscaneado.Text=""	
	Try
		OCRPreview.startScanning		
	Catch
		Log(LastException)
	End Try
        '
	OCRPreview.Visible=True
End Sub


Private Sub OCRCameraDesligar_Click
	'
	' Finish OCR. Turn off camera.
	'
	Try
	        OCRPreview.stopScanning		
	Catch
		Log(LastException)
	End Try
	OCRPreview.Visible=False
	OCRPainel.Visible=False
	PainelTela.Visible=False
End Sub


Private Sub OCRLer_Click
	'
	' To take a text from camera
	'
	Private Blocos   As List
	Private Texto    As String
	Private Altura   As Int
	Private Contador As Int
	'
	' Start Scan
	'
	Try
		OCRPreview.startScanning
	Catch
		Log(LastException)
	End Try
	Sleep(0)
	'
	' Blocos
	'
	Blocos.Initialize
	Blocos = OCRPreview.TextBlocks
	'
	'  Turn scan off
	'
	Try
		OCRPreview.stopScanning
	Catch
		Log("Nada")
	End Try
	'
	OCRPreview.Visible=False
	Sleep(0)
	'
	If (Blocos.IsInitialized=False) Then
		Texto=""
	Else
		'
		For Contador = 0 To Blocos.Size - 1
			Texto = Texto & Blocos.Get(Contador) & CRLF
		Next
	End If
	'
	Texto=Texto.Trim
	'
	If (Texto="") Then
		Texto=MsgOCRNaoFoiPossivelLer & CRLF
	End If
	'
	Texto=AFFuncoes.Left(Texto,Texto.Length-1)
	OCRTextoEscaneado.Text=Texto
	'
	Altura=StringUtilities.MeasureMultilineTextHeight(QRCodeTextoEscaneado,Texto)
	OCRTextoEscaneado.Height=Altura
	OCRScroll.Panel.Height=Altura
End Sub
 

Johan Schoeman

Expert
Licensed User
Longtime User
Hard to tell without a sample project. Dont know from your code what panel is a parent or a child.
 

adriano.freitas

Active Member
I understand, but in fact the project itself is big and would generate more confusion. What I could say is that with regard to OCR there is nothing more. And as a parent I use a simple panel, the size of the entire screen... but anyway, I'll see if I can create a small project that replicates the problem and send it.

Thank you for your attention!
 

Ebic

Member
Licensed User
Longtime User
Hi Joh, congratulations for this beautiful library.
I wanted to make a request: is it possible to save the image that comes
scanned for a different use?
Thank you.
 

Johan Schoeman

Expert
Licensed User
Longtime User
Hi Joh, congratulations for this beautiful library.
I wanted to make a request: is it possible to save the image that comes
scanned for a different use?
Thank you.
Not sure this lib is still relevant. ML Kit should be the new to go if I am not mistaken.
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…