how to get text from region and save at array?????

Asked by Nurbergen

????????????????????

Question information

Language:
English Edit question
Status:
Answered
For:
SikuliX Edit question
Assignee:
No assignee Edit question
Last query:
Last reply:
Revision history for this message
aidma (aidan-mahler13) said :
#1

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.

Can you help with this problem?

Provide an answer of your own, or ask Nurbergen for more information if necessary.

To post a message you must log in.