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

    Status: Open => Answered

RaiMan proposed the following answer:
-- 1: your code as such is ok - no need for being nauseous ;-)

-- 2: use of exists()
in your case, supposing that the number is already visible at the time the loop 
starts, use exists(..., 0), which restricts each search to only one search 
trial. 

-- 3: exists() does not seem to be necessary at all:
 foundNumbers = []
 minScore = 0.95
 for i in range(9): # range starts with 0 anyway
            matches = rollRegion.findAll(numbPattern[i][1])
            if matches.hasNext():
                 while matches.hasNext()
                     match = matches.next()
                     if match.getScore() > minScore:
                         foundNumbers.append((i, match.x))

-- 4: quality of number shots
you should rework your number shots, especially that of 8 and 0, which seem to 
have possible scores, that might lead to false positives (as little background 
as possible around the numbers).

-- 5:
Then I recommend to use individual scores for each number, that you have 
evaluated before:
numbPattern = [(0,Pattern("num0.png").similar(individualScore)), ..., ... ]

now you can code:
 foundNumbers = []
 for i in range(9): # range starts with 0 anyway
            matches = rollRegion.findAll(numbPattern[i][1])
            if matches.hasNext():
                 while matches.hasNext()
                     match = matches.next()
                     foundNumbers.append((i, match.x))

-- 6: check if a number slot has already been identified
after having implemented step 5, you should sort the rollRegion manually, so 
that the number with the highest score comes first, than the next with the next 
lower score and so on.
Now you can implement another check: if any number later is matched again for 
the same slot (x value), then just forget it.

matchInFoundNumbers():
   for found in foundNumbers:
       if (match.x > found.x - 2 and match.x < found.x +2): return true # +-2 
need possibly be adjusted 
       return false 

 foundNumbers = []
 for i in range(9): # range starts with 0 anyway
            matches = rollRegion.findAll(numbPattern[i][1])
            if matches.hasNext():
                 while matches.hasNext()
                     match = matches.next()
                     if (not matchInFoundNumbers()):
                         foundNumbers.append((i, match.x))

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

_______________________________________________
Mailing list: https://launchpad.net/~sikuli-driver
Post to     : [email protected]
Unsubscribe : https://launchpad.net/~sikuli-driver
More help   : https://help.launchpad.net/ListHelp

Reply via email to