How to use OCR(optical character recognition) in python?

Asked by Yashwanth N

Hi,

Is it possible to write a python script for the following?
1> use sikuli to capture image, store it in .png format
2> write a python script to extracts text from sikuli image.
3> After extracting it should looks for user input text in that extracted text.
4> If it found, It should send this text to sikuli to find position in the image and click on that.

Thanks,

Question information

Language:
English Edit question
Status:
Solved
For:
SikuliX Edit question
Assignee:
No assignee Edit question
Solved by:
RaiMan
Solved:
Last query:
Last reply:
Revision history for this message
Best RaiMan (raimund-hocke) said :
#1

Sikuli Script (and hence the Sikuli IDE) uses Python language (level 2.5), but the interpreter used is Jython 2.5 (which comes bundled with Sikuli). Jython is Java based and so all Python-only modules should work, which means, that Python modules (like PIL) containing C-based stuff cannot be used. On the other side, everything available in the Java world can be imported and used.

at 1>
import shutil
img = capture(some_region)
shutil.move(img, "to_other_place_you_need_name.png")

at 2>
If you have a solution, that only works in Python (aka needs C-Python interpreter), you might do that.
Sikuli has an OCR feature based on Tesseract 2, that might deliver sufficient results:

text = some_region.text()

but mind bug 710586

at 3>
do it in- or outside Sikuli

at 4>
Sikuli can search for text with the same restrictions as for >2

some_region.find(some_token_text)

and of course
click(some_token_text)

Revision history for this message
Yashwanth N (yashthekool2009) said :
#2

Thanks RaiMan, that solved my question.

Revision history for this message
JonyGreen (jonygreen) said :
#3

I'm not a developer, i always use the free online ocr http://www.online-code.net/ocr.html to recognize and scan text from image.