Hi, I made a tesseract-ocr ui frontend, which will convert images stored in the clipboard into texts. Different from https://www.b4x.com/android/forum/threads/screen-ocr-in-5-minutes-and-50-lines.90655/, my version is very simple. It utilizes the system's screencapture shortcut to store images...
www.b4x.com
I tested the application and it works very well but it is a desktop application.
and I don't know how I can do this in b4j server.
In desktop app:
Dim out As OutputStream
out=File.OpenOutput(File.Combine(File.DirApp,"tesseract-ocr"),"image.png",False)
ImageView1.GetImage.WriteToStream(out)
out.Close
and tried to do this without success:
bj4[server]:
Dim out As OutputStream
out=File.OpenOutput(File.Combine(File.DirApp,"tesseract-ocr"),"image.png",False)
Dim nombreArchivoTemporal As String = Main.NombreArchivo
Dim imageData() As Byte = File.ReadBytes(File.DirApp & "/up", nombreArchivoTemporal)
Dim lengnt As String = nombreArchivoTemporal.Length
out=File.OpenOutput(File.Combine(File.DirApp,"tesseract-ocr"),"image.png",False)
out.WriteBytes(imageData, 0, lengnt)
out.Close
Sub Handle(req As ServletRequest, resp As ServletResponse)
Try
Dim img() As Byte = FileToBytes(File.DirAssets,"no_image_available.png")
Dim Inp As InputStream
Inp.InitializeFromBytesArray(img, 0, img.Length)
File.Copy2(Inp, resp.OutputStream)
StopMessageLoop
Catch
Log(LastException)
End Try
End Sub
Sub FileToBytes (Dir As String, FileName As String) As Byte()
Return Bit.InputStreamToBytes(File.OpenInput(Dir, FileName))
End Sub
Sub Handle(req As ServletRequest, resp As ServletResponse)
Try
Dim img() As Byte = FileToBytes(File.DirAssets,"no_image_available.png")
Dim Inp As InputStream
Inp.InitializeFromBytesArray(img, 0, img.Length)
File.Copy2(Inp, resp.OutputStream)
StopMessageLoop
Catch
Log(LastException)
End Try
End Sub
Sub FileToBytes (Dir As String, FileName As String) As Byte()
Return Bit.InputStreamToBytes(File.OpenInput(Dir, FileName))
End Sub
Sub ProcessImage
Try
' Patch of the upload image.
Dim uploadedImagePath As String = File.Combine(File.DirApp & "/up", "")
' Open OutputStream for output image
Dim Inp As InputStream = File.OpenInput(uploadedImagePath,Main.NombreArchivo)
' Open OutputStream for output image
Dim out As OutputStream = File.OpenOutput(File.DirApp & "/tesseract-ocr", "image.png", False)
' Copy image from InputStream to OutputStream
File.Copy2(Inp, out)
' Close streams
out.Close
' Here you can call Tesseract or do any additional processing with the image.
scan
Catch
Log(LastException)
End Try
End Sub