sikuli-driver team mailing list archive
-
sikuli-driver team
-
Mailing list archive
-
Message #41580
[Question #466210]: 'findAll(): 'NoneType' object is not iterable' due to inconsistent image recognition?
New question #466210 on Sikuli:
https://answers.launchpad.net/sikuli/+question/466210
Hi there,
I have written a script in SikuliIDE 1.1.0 nightly on an up-to-date Arch Linux system. The script works, well, kind of. It is supposed to run indefinitely but every now and then it stops and throws a 'findAll(): 'NoneType' object is not iterable'.
The script is meant to check the screen for random numbers (between 75-108) in a specific location, recognizing the numerical value, clicking one button on the screen ('store') if it happens to be the highest number as of yet, and keep clicking on another button ('reroll') on the screen to generate a new random number. The idea is to keep going until the user stops the script while storing the highest number along the way.
The script is using cropped images of the numbers as they might appear on the screen. A loop checks for the respective image of every number, then uses findAll() to see how many occurances it can find, then sorts them according to their X coordinate and finally puts them together and converts them to an integer. Then it starts over again.
Settings.MinSimilarity = 0.95
numbPattern = [(0,"num0.png"),(1,"num1.png"),(2,"num2.png"),(3,"num3.png"),(4,"num4.png"),(5,"num5.png"),(6,"num6.png"),(7,"num7.png"),(8,"num8.png"),(9,"num9.png")]
for i in range(0, 9):
if rollRegion.exists(numbPattern[i][1]):
currentRollRaw = list(rollRegion.findAll(numbPattern[i][1])) #error appears here (happens occasionally)
y = i
for n in range(len(currentRollRaw)):
coordRoll = currentRollRaw[n].getX()
x.append((y,coordRoll))
else:
pass
Sometimes numbers don't get recognized correctly (due to my script, not due to Sikuli); eg. 84 on the screen would be recognized as 804 by my script. However, this only happens from time to time. Usually the image recognition is consistent. Numbers above 108 are simply omitted by the script (a not so elegant solution, but still).
I suspect that sometimes 'exists' in the for loop finds a certain number, but then findAll() fails to find it (or them) and thus 'Using findAll(): 'NoneType' object is not iterable' terminates the running script. This is due to Sikuli which doesn't recognize the number images consistently.
How can this be avoided? I hope that my explanation is understandable. My apologies in advance if this code makes any veteran programmer nauseous.
--
You received this question notification because your team Sikuli Drivers
is an answer contact for Sikuli.