← Back to team overview

sikuli-driver team mailing list archive

Re: [Question #259550]: issue in comparing two images

 

Question #259550 on Sikuli changed:
https://answers.launchpad.net/sikuli/+question/259550

RaiMan proposed the following answer:
@Eugene
thanks for the example.

I do not know, what you mean by "Java API it's already solved", but your
example fails on all levels, but has a workaround.

The reason behind has nothing to do with some "color-strict flag", since
there is none available.

If you use your 2 images you will get the following result (supposing the coloured is the pressed version):
pressed matches pressed with 1.00, but unpressed only with 0.97
unpressed matches both pressed and unpressed with 1.00

this leads to the workaround:
unpressed = Pattern("unpressed.png").exact()
pressed = Pattern("pressed.png").exact()

button = find(unpressed)
# now we can check the found button
if button.grow(10).exists(pressed, 0):
    print "button is pressed"
else:
    print "button is not pressed"

the .grow(10) extends the match region to be robust against differences
in the shots (width/height).

Another possibility using only the pressed image (which makes it more robust with respect to the mentioned shot problem):
button = Pattern("pressed.png").similar(0.95)
pressed = Pattern(button).exact()
mButton = find(button)
# now we can check the found button
Settings.CheckLastSeen = False # see comment
if mButton.exists(pressed):
    print "button is pressed"
else:
    print "button is not pressed"
Settings.CheckLastSeen = True # see comment

comment:
version 1.1.0 has a feature, that stores the last match with the image and with the next search the image is first searched, where it was before, which speeds things up with a factor 50 ... 100.
In this special case it leads to a problem (I will fix that).
So for now we have to switch the feature off  for the check and on again afterwards.

The real reason of the initial problem I guess is the fact, that internally the score is rounded at the second decimal (0.99+ is exact and reported as 1.00). In your case, on some decimal position 2+, we might find differences in the score.
In version 1.2 I will revise the score handling anyway, so it might well be, that your case will be handled as expected.

If you have more than one of these buttons visible in this moment, you
have to use findAll() and scan the matches.

-- 
You received this question notification because you are a member of
Sikuli Drivers, which is an answer contact for Sikuli.