Share My Creation Screen OCR in 5 minutes and 50 lines!

upload_2018-3-14_20-44-19.png



Exactly like the thread title! 5 minutes. 50 lines...

1 - Download and install Tesseract (<15Mb): https://sourceforge.net/projects/tesseract-ocr-alt/files/
2 - Install Tesseract in "C:\TO" - OR change the DoOcr sub to match the location where you installed it
3 - Start the program. Move the frame to the position of the screen where the text to be read is.
4 - Click OCR!
5 - That's it!
 

Attachments

  • OCR5min.zip
    41.9 KB · Views: 565

roberto64

Active Member
Licensed User
Longtime User
hi, com libjAWT Robot ver. 1.55 does not recognize the commands,"c3po.runCommand"-"c3po.rectangleAsArbitrary"-"c3po.CreateScreenCaptureToFile"
B4X:
Sub DoOCR
 
    c3po.runCommand("C:\TO\tesseract frame.png text")
End Sub
error
Sub ScreenCapture
    c3po.rectangleAsArbitrary(OCRFrame.f.WindowLeft, OCRFrame.f.WindowTop, OCRFrame.f.Width, OCRFrame.f.Height)
    c3po.CreateScreenCaptureToFile("Frame.png")
End Sub
 

jroriz

Active Member
Licensed User
Longtime User
hi, com libjAWT Robot ver. 1.55 does not recognize the commands,"c3po.runCommand"-"c3po.rectangleAsArbitrary"-"c3po.CreateScreenCaptureToFile"
B4X:
Sub DoOCR
 
    c3po.runCommand("C:\TO\tesseract frame.png text")
End Sub
error
Sub ScreenCapture
    c3po.rectangleAsArbitrary(OCRFrame.f.WindowLeft, OCRFrame.f.WindowTop, OCRFrame.f.Width, OCRFrame.f.Height)
    c3po.CreateScreenCaptureToFile("Frame.png")
End Sub

Roberto deve ser brasileiro... Tem um monte de jeito de resolver isso. Um deles é usar a 1.0 (anexa).

Pode também usar o jshell:

B4X:
Sub DoOCR
    Dim shl As Shell
    shl.Initialize("", "C:\TO\tesseract", Array As String("frame.png", "text"))
    shl.WorkingDirectory = File.DirApp
    shl.Run(1000)
    'c3po.runCommand("C:\TO\tesseract frame.png text")    ' change tesseract folder if needed
End Sub
 

Attachments

  • jAWTRobot.jar
    7.6 KB · Views: 418
  • jAWTRobot.xml
    18.6 KB · Views: 427
Last edited:

jroriz

Active Member
Licensed User
Longtime User
Hi:jroriz Can use Chinese, I copy chi_sim.traineddata into tesseract-OCR\tessdata ,But can,t use

Hi.
You will need to change
c3po.runCommand("C:\TO\tesseract frame.png text")
to
c3po.runCommand("C:\TO\tesseract frame.png text -l chi_sim")

There are newer versions of tessdata, with better-trained files.
Google it and make tests.

Note that there are other parameters you can try:

Usage:tesseract imagename outputbase [-l lang] [-psm pagesegmode] [configfile...
]

pagesegmode values are:
0 = Orientation and script detection (OSD) only.
1 = Automatic page segmentation with OSD.
2 = Automatic page segmentation, but no OSD, or OCR
3 = Fully automatic page segmentation, but no OSD. (Default)
4 = Assume a single column of text of variable sizes.
5 = Assume a single uniform block of vertically aligned text.
6 = Assume a single uniform block of text.
7 = Treat the image as a single text line.
8 = Treat the image as a single word.
9 = Treat the image as a single word in a circle.
10 = Treat the image as a single character.
-l lang and/or -psm pagesegmode must occur before anyconfigfile.

Single options:
-v --version: version info
--list-langs: list available languages for tesseract engine

Hugs.
 
Last edited:

supriono

Member
Licensed User
Longtime User
View attachment 65504


Exactly like the thread title! 5 minutes. 50 lines...

1 - Download and install Tesseract (<15Mb): https://sourceforge.net/projects/tesseract-ocr-alt/files/
2 - Install Tesseract in "C:\TO" - OR change the DoOcr sub to match the location where you installed it
3 - Start the program. Move the frame to the position of the screen where the text to be read is.
4 - Click OCR!
5 - That's it!

i found this error
Cannot run program "C:\TO\tesseract": CreateProcess error=2, The system cannot find the file specified
 

DonManfred

Expert
Licensed User
Longtime User
i found this error
Cannot run program "C:\TO\tesseract": CreateProcess error=2, The system cannot find the file specified
2 - Install Tesseract in "C:\TO" - OR change the DoOcr sub to match the location where you installed it

Did you adapt the code to match the folder where you installed it?
 
Top