sikuli-driver team mailing list archive
-
sikuli-driver team
-
Mailing list archive
-
Message #31116
Re: [Question #263735]: how to get text from region and save at array?????
Question #263735 on Sikuli changed:
https://answers.launchpad.net/sikuli/+question/263735
Status: Open => Answered
aidma proposed the following answer:
First you need to get the text from a region and store it in a variable.
For example, I have a region with the text:
The quick brown fox jumps over the lazy dog
and I know that region is defined by Region(0, 50, 600, 300)
[http://sikulix-2014.readthedocs.org/en/latest/region.html] . Because
sikuli code is written in python, I'm going to save the text into a
list, not an array. I'm going to split the text into the list at every
SPACE. (you can split it up differently if you'd like)
So, I write my Sikuli code into the SikulixIDE 1.1.0 editor:
====================== CODE =======================
# Ensure Ocr is turned on (you must have chosen the correct
# sikuli-setup options to use these Settings)
Settings.OcrTextSearch = True
Settings.OcrTextRead = True
# Define my Region
textRegion = Region(0,50,600,300)
# Grab text from my region and store it in the strText variable
# textRegion.text() will return a string
strText = textRegion.text()
# Divide the contents of strText into an array, using the SPACE
# character as the delimiter
listText = strText.split(" ")
# Now listText contains text from a region in an array.
print "strText: ", strText
print "listText: ", listText
===================================================
When Run, this code outputs:
==================== OUTPUT =======================
strText: Thequick brown fox jumps over the lazy dog
listText: ['Thequick', 'brown', 'fox', 'jumps', 'over', 'the', 'lazy', 'dog']
===================================================
As you can see, a small mistake was made: the space between "The" and
"quick" was missed. OCR in sikuli is still very experimental and doesn't
work perfectly. Only use it if you accept its inaccuracies.
--
You received this question notification because you are a member of
Sikuli Drivers, which is an answer contact for Sikuli.