Best practice ?

Asked by Peter Sandberg

Hi,

I'm new to Sikuli, and have been reading the documents (well, not all details....) and I have also got the system up and running, studied Phyton and also been able to get something running.

However, before I start trying to find the best way to do what I'm trying, then maybe ask the community to get some input.

In short I'm making a script for a game, and within a region I need to recognise up to a 100 different patterns and react to these.

When a patter is recognised, then I need to click on it, which opens a new window, and then click on this (same for all recognised patterns).

I have made a concept where I look for each individual pattern (smallest size possibe), but the number adds up...

I have also thought, just to look for when the background changes, but i also need to click in the area in which the patter pops up...

Any suggestions for how to do this?

Peter

Question information

Language:
English Edit question
Status:
Solved
For:
SikuliX Edit question
Assignee:
No assignee Edit question
Solved by:
RaiMan
Solved:
Last query:
Last reply:
Revision history for this message
RaiMan (raimund-hocke) said :
#1

looking for 100 patterns in one region at the same time is really challenging.

I guess you currently loop around 100
if region.exists(pattern, 0)

hopefully baked into a def and having the patterns in a list.

If everything goes well and all is optimized (smallest region possible) the average match time for one of the patterns should be somewhere between 5 and 10 seconds (assuming 100 msec per search and 100 patterns)

If this is not sufficient, then the only chance to get faster with pattern search is to use observe in background with different region objects (for the same area on screen) and groups of patterns, to delegate the search into a reasonable amount of parallel threads (assuming a capable system).

You might as well try to use observe with onChange() in the given region. You would at least find the area where something changed, but this still leaves you with the need to find out, what pattern popped up.
Supposing, that in this case, the region to look in, has the size of the patterns, then it might be possible to find out which pattern appeared within on second in average (assuming 10 msec per search and 100 patterns).

as already mentioned: challenging ;-)

Revision history for this message
Peter Sandberg (pesan) said :
#2

Thanks very much !

I have not yet got to make it smart with lists etc. Wanted to get a feel for how it works first, and I'm very rusty in programming and have not used Phyton before. Actually, quiet easy to use Sikuli, great to do some pgm. again, and fun to try Phyton.. :-)

Below is what I have done. Seems to work fine, but a bit slow when not finding the patterns. I probably need to look at some of the settings....

Thanks again Peter

-------

setFindFailedResponse(SKIP)
loc = Region(1195,611,378,141)
loc2 = Region(465,726,722,78)

while 1 > 0:
    if loc.exists("1468520600614.png"): doubleClick("1468520600614.png")
    elif loc.exists("1468521696872.png"): doubleClick("1468521696872.png")
    elif loc.exists("1468567647117.png"): doubleClick("1468567647117.png")
    elif loc.exists("1468521957543.png"): doubleClick("1468521957543.png")
    elif loc.exists("1468522053608.png"): doubleClick("1468522053608.png")
    elif loc.exists("1468522119471.png"): doubleClick("1468522119471.png")
    elif loc.exists("1468522188185.png"): doubleClick("1468522188185.png")
    elif loc.exists("1468522337050.png"): doubleClick("1468522337050.png")
    if loc2.exists("1468521813016.png"): click("1468521813016.png")

Revision history for this message
Best RaiMan (raimund-hocke) said :
#3

--- but a bit slow when not finding the pattern
... that is because of the standard waiting time of 3 seconds.
There is a global, a region and a function setting to influence this waiting time. I prefer the function, because then it is more obvious:

if loc.exists("1468520600614.png", 0): doubleClick("1468520600614.png")

... the ,0 tells the search to give up after the first try, which should let it come back after some 10 milliseconds with this rather small region loc even in case it is not there.

this should be suitable for all the loc.exists().
the loc2.exists() should be left without the ,0, so it waits for the visual to appear, since I suppose, this only fires, if one of the doubleClicks before happened.

one more thing:
a region remembers the last match, so this is more convenient:
if loc.exists("1468520600614.png", 0): loc.doubleClick()
... in case of found, the center of the remembered match would be clicked without an additional search for what was already found just before.

If the resulting timing now is sufficient, then this is the easiest and most straightforward solution.

Revision history for this message
Peter Sandberg (pesan) said :
#4

Thanks RaiMan, that solved my question.

Revision history for this message
Peter Sandberg (pesan) said :
#5

Thanks !! :-) Peter