sikuli-driver team mailing list archive
-
sikuli-driver team
-
Mailing list archive
-
Message #22466
Re: [Question #239619]: need to speed up the code
Question #239619 on Sikuli changed:
https://answers.launchpad.net/sikuli/+question/239619
Status: Open => Answered
RaiMan proposed the following answer:
- for RC3 and 1.0.1 the minimum turnaround time for one search is the
time given by the Settings.WaitScanrate which is 3 (means 300 msec min
turnaround time per search). Though exists(image,0) comes back after the
1st search, it currently (a bug ;-) consumes the 300 msecs. So raising
the scan rate temporarily to 500 (= 2 msecs min turnaround), would
release this brake.
On faster machines currently the search time for small regions (yours is nearly small ;-) can be as short as a few msecs.
So principally it should be possible to search about 20 - 30 elements per second (so your target of 300 in 15 secs should be achievable).
What you have to do (with version 1.0.1)
r2= Region(Region(882,849,340,166))#trigger region, runs with scan rate 3
Settings.waitScanRate = 500 # release brake for the exists
r = Region(Region(734,589,410,247)) # runs with scan rate 500
Settings.waitScanRate = 3 # reset to normal
while (count < 10):
.......
Currently (another bug with 1.0.1) the scan rate has to be changed
before the region is created.
Version 1.1 will have some optimizations and the above bugs will be
fixed.
One more thing:
you should organize your images in a list:
images = []
images.append(Pattern("10S-AH.png").similar(0.99))
images.append(Pattern("10S-AP.png").similar(0.99))
....
and make a function
def existsAny(reg, imageList):
for img in imageList:
if (reg.exists(img, 0)):
return True
return False
and your loop will look like that:
while (count < 10):
r2.wait(Pattern("trigger.png").similar(0.90), FOREVER)#trigger
img = Screen(0).capture(Region(822,638,231,141))
import shutil
shutil.move (img, 'c:/a/a(%d).png' % count)
count = count + 1
if (existsAny(r, images)):
img = Screen(0).capture(Region(725,389,490,105))
import shutil
shutil.move (img, 'c:/a/b(%d).png' % count)
doubleClick(Region(1332,817,74,34))
doubleClick(Region(1391,908,215,83))
else:
doubleClick(Region(882,849,340,166))#clicking the trigger restarts the loop.
BTW: --- so problably my code is looking like shit. ---
scripts written in a scripting language like Python tend to always look like shit: that is due to the freedom you have.
At least the one-line-is-one-statement and the indentation rule in Python makes it look a bit more structured than other scripting languages like Ruby, that have { } to denote blocks, that do not have an automatic structure (you could write the whole script in one line ;-).
Another automatic is: the larger the scripts get, the more you will get
more disciplined and structured just as a self defense.
--
You received this question notification because you are a member of
Sikuli Drivers, which is an answer contact for Sikuli.