What can I do to prevent a ~300ms delay when an image is NOT found? (Sikuli 1.0.1, Java, Windows)

Asked by joseytw

Hello,

I have searched the forums and while I have read posts that seem to apply to the problem I am having, I can not nail down a workable solution. I am using Sikuli 1.0.1, and I am coding in Java on a Windows 7 machine. I am also fairly new to coding in Java and using Sikuli.

My problem is this:

I have an array of 10 small images (10x15 pixles in size) that I iterate through looking for a match using r.exists (the region is 12x17 pixels) and when a match NOT found there seems to be a delay of ~300 ms before the next check is made.

Here is the code:

int i =0;
for(Pattern p : pNumberArray){
    if(r.exists(p.similar(.9f), 0) != null){
        System.out.println(library.getTime() + " Image Found : " + p);
    return i;
    }
    System.out.println(library.getTime() + " Image not found : " + p);
    i++;
}

Here is the result when I run the above code.

12:19:01:032 Image not found
12:19:01:365 Image not found
12:19:01:698 Image not found
12:19:02:031 Image not found
12:19:02:364 Image not found
12:19:02:697 Image not found

I was hoping using a 0 for (r.exists(p/similar(.9f), 0) would fix the 300ms delay problem but it does not.

I then read up on 'Settings.AutoWaitTimeout' (https://answers.launchpad.net/sikuli/+question/251337) but ruled it out as not applicable in my case. As I understand it, using the 0 in (r.exists(p/similar(.9f), 0) forces a one time check of the image and immediately returns the match if found or NULL if not (https://answers.launchpad.net/sikuli/+question/251337), so there should be NO delay in a response whether an image is found or not.

Searching forum posts turned me on to 'Settings.ScanRate' (https://answers.launchpad.net/sikuli/+question/194144) so I tried setting 'Settings.WaitScanRate = 100;' so that it would search for a match for no more than .01 seconds and return the result, but changing that setting had no effect. I also tried a variety of values including, 500, 1, .1f, and .01f but the results when running the code above was always the same with ~300 ms delay.

So all that being said, that leads to my questions:
1) I assumed that setting the timeout to 0 when using exists on a region (r.exists(p/similar(.9f), 0) would result in NO delay in a response whether an image is found or not. That is not the case. Why is there a ~300 when the timeout is set to 0?

2) I assumed that setting 'Settings.WaitScanRate = 100;' would force a search result at the end of .01 seconds. It does not. Am I missing something about how this works?

3) One post I read mentioned that there used to be an issue setting the values of Settings fields wouldn't work because the variables used a 'protected' modifier, but I can change the value and see the results of modifying the value between 'Settings.MoveMouseDelay = 1;' and 'Settings.MoveMouseDelay = 0;' so that leads me to believe that I can change the value of Settings fields. Is the 'Settings.WaitScanRate' indeed a protected variable and one that I cannot change?

4) I can't imagine it taking ~300ms to match a 10x15 pixel image in a 12x17 pixel search region. That 300ms isn't the amount of time it takes to actually search for a match in the region is it?

I spent hours and hours and hours reading forum posts and experimenting with different code combinations but I can't get rid of the ~300ms delay when an image is NOT found.

Thanks in advance for any wise words of wisdom!

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
joseytw (joseytw) said :
#1

Ahhh geez, I just looked in the bug section. I didn't think to check there because I assumed it was working correctly. It looks like this was bugged in 1.0.1 and slated for fix in 1.1.0:

https://bugs.launchpad.net/sikuli/+bug/1241993

So I am guessing that is the problem right there... and after all of these hours banging my forehead onto my desk if I had just checked one last place (bugs) I would have had my answer.

 Le sigh. :)

Just so I am clear, using a 0 for (r.exists(p/similar(.9f), 0) in combination with 'Settings.WaitScanRate = 100;' (when it is working) should make it so that a return is made in .01 seconds, correct?

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

-- yes, the problem is fixed in 1.1.0

-- (r.exists(p/similar(.9f), 0)
will return after the time needed to find p in r, which depends on the sizes of r and p

using a waittime of 0, lets the search always return after one try. So in this case WaitScanRate is not relevant.

WaitScanRate defines how often the search is repeated during the waittime, if waittime > 0

Settings.WaitScanRate = 100;
would only make sense, if the search time in the average is less than 10 millisecs (which only is the case with very small regions).
the standard WaitScanRate is 3. Higher values usually only lead to constant search, since the average search time is greater than the scan interval of some 10 millisecs.
Constant search is very greedy, since it is plain number crunching.

Revision history for this message
joseytw (joseytw) said :
#3

Thanks RaiMan, that solved my question.