← Back to team overview

sikuli-driver team mailing list archive

Re: [Question #466210]: 'findAll(): 'NoneType' object is not iterable' due to inconsistent image recognition?

 

Question #466210 on Sikuli changed:
https://answers.launchpad.net/sikuli/+question/466210

    Status: Open => Answered

RaiMan proposed the following answer:
ok, might all be a little bit complex for a newbee.
I revised the situation and possible solutions and found that the following is the most effective one.

the steps:
- I manually created 10 images of 8x13 for the possible digits (_numN.png) (the _ is a defined precaution for images never be deleted automatically)
- I evaluated the region of number in question: max 6 digits in my case
- I defined a cell width and the steps to walk through the number from left to right with this cell and evaluate each digit using an exists() loop
- to adjust accuracy, I made some tests, to know the minimum similarity needed, to identify each digit (e.g. 0, 8, 6,9 are very similar)

the script can be downloaded from here: (it is zipped)
http://snippets.sikuli.de/examples/nums.sikuli.zip

I used a webpage as testcase, that generates random numbers - in my case between 1 and 1000000 
http://www.randomnumbergenerator.com

as a reference I use the click button "Generate number" to evaluate the
region that contains the 6-digit number.

To run a test, just prepare the website as I did and run.
If you comment out the lines with the highlight()'s, it runs rather fast.

******* the script text *******
# the manually created digit images
nums = []
for n in range(10):
  nums.append("_num%d.png" % n)
  
# the website http://www.randomnumbergenerator.com
# must be the frontmost window in a browser
# evaluate the region of the number 
imgRef = "imgRef.png"
number = find(imgRef).right(1).right(171).right(1).right(60)
number.highlight(3) # the region that contains the number

# the first cell from left containing a digit
number = find(imgRef).right(1).right(169).right(15)

result = "" 
# walk through the possible 6 cells
for n in range(6):
  number.highlight(1) # the cell
  # try the digit, first match wins
  for k in range(10):
    if number.exists(Pattern(nums[k]).similar(0.81), 0):
      print n, k, number.getLastMatch().getScore()
      result += str(k)
  number.x += 10 # switch to the next cell

# the evaluated number
print "the number:", result

-- 
You received this question notification because your team Sikuli Drivers
is an answer contact for Sikuli.