← Back to team overview

sikuli-driver team mailing list archive

[Question #674239]: What's really happening when you run exists(Pattern, 0)?

 

New question #674239 on Sikuli:
https://answers.launchpad.net/sikuli/+question/674239

I wrote a wrapper method to iterate through a set of Patterns and check exists(Pattern, 0) on them to see whether any of them exists.

I'm using this to check for slightly different, but all valid, versions of a graph. For one graph I have only two valid pngs; for another I have only one. For these graphs, exists() does not match the correct chart the first time through the loop, but it does match the second time (the loop runs until a specified timeout). 

I'm wondering why the first try of exists() for the correct png didn't match, but the second one did.

Here's a code snippet and some log results:

public static boolean multiPatternExists(@NotNull final Region region, @NotNull final Map<String, Pattern> patterns, final long timeoutMs, final float similarity, final String... patternsToMatch) {
    if (timeoutMs < 0) {
        throw new IllegalArgumentException("timeoutMs cannot be negative.");
    }
    final long start = System.currentTimeMillis();
    boolean found = false;
    while (System.currentTimeMillis() < start + timeoutMs && !found) {
        for (final String patternName : patternsToMatch) {
            final Pattern testPattern = patterns.get(patternName);
            if (testPattern != null) {
                Debug.action("Trying " + patternName);
                if (region.exists(testPattern.similar(similarity), 0) != null) {
                    found = true;
                    Debug.action("Match found with " + patternName);
                    break;
                }
            } else {
                Debug.action("Pattern: " + patternName + " not found in patterns map.");
            }
        }
    }
    return found;
}

[log] CLICK on L(433,600)@S(0)[0,0 1920x1080] (625 msec)
[log] Trying ohlcPlotByChart.png
[log] Trying ohlcPlotByChart2.png
[log] Trying ohlcPlotByChart.png
[log] Trying ohlcPlotByChart2.png
[log] Match found with ohlcPlotByChart2.png

Thanks,
Paul

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