Find gives different result when using Pattern attributes on code than using the IDE pane

Asked by unomartin on 2020-04-30

I have some images that are of different size than the ones on screen, so I made a script to find which resize and similarity parameters best ressemble what its displayed.
What I got is that the script gets a match on every size and similiarity value, however the Pattern preview pane on the IDE works as intended and matches with similarity values of 0.88 and less (though it doesn't seem to use the resize value).
It's not clear to me if I'm doing something wrong so I leave the short script here so you can look at it and find if there is any way to make it work with SikuliX.
Ninja edit: I'm using SikuliX 2.04 IDE on a VM with Win 7 Pro 64bits
***
import csv

raw = []
laps = 5
relevant_area = Region(150,585,55,55)
fieldnames = ['SIZE', 'PRECISION', 'AVG_SCORE', 'COUNT']
with open('O:\\best_pattern_modifiers_output.csv', mode='wb') as csv_file:
    output_writer = csv.writer(csv_file, dialect='excel', delimiter=';')
    output_writer.writerow(fieldnames)
    for precision in range(51, 101):
        for size in range(50,101, 10):
            for lap in range(laps):
                found_match = relevant_area.exists(Pattern("icon_selection_small_left_t_s.png").resize(round(size / 100, 1)).similar(precision / 100).mask(), 0)
                if found_match:
                    raw.append(found_match.getScore())
            n = len(raw)
            if n >= (int(round(laps / 2)) + 1):
                avg = round(sum(raw) / n, 2)
                output_writer.writerow((size, precision, avg, n))
            raw = []

Question information

Language:
English Edit question
Status:
Answered
For:
Sikuli Edit question
Assignee:
No assignee Edit question
Last query:
2020-04-30
Last reply:
2020-04-30
RaiMan (raimund-hocke) said : #1

I do not understand the inner loop (range(laps)), which simply does 5 times the same exists()?

What is the intention to use Pattern()......mask()?

If only the size of the image varies, then a repeated exists() would be sufficient with the image resized with a stepping of 1 pixel between a min-size and a max-size should reveal a match with the best score.

Hence you have to calculate the resize factor out of the width or height.

Can you help with this problem?

Provide an answer of your own, or ask unomartin for more information if necessary.

To post a message you must log in.