Sikuli can't distinguish checked and unchecked box.

Asked by Landy

From this link http://sikuli.org/docx/tutorials/uncheckall/uncheckall.html, it looks like Sikuli can distinguish checked box and unchecked box. But in my case, it fails.

My environment:
Windows 7 x64
Sikuli X-1.0rc2

I've a Win32 application, and there is one (and only one) check box in a panel. My code is like:
with Region(r):
    if exists("checked.png"):
        popup("checked")
    if exists("unchecked.png"):
        popup("unchecked")

I execute my code, then get 2 popups for both checked and unchecked. But there is only one check box and should only one popup in a execution....

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
Best RaiMan (raimund-hocke) said :
#1

This might well be, depending on the images you have taken from the checkboxes in the two states (checked/unchecked).

The search algorithm says found, if the match has a score of at least 0.7. This seems to be in both cases, but they have different scores.

I would suggest, to only look for the checked version, e.g.

with Region(r):
    if exists("checked.png"): popup("checked")
    else: popup("unchecked")

next I would make a simple test:
print Region(r).find("checked.png")
Region(r).getLastMatch(highlight(3)

this should print something like:
Match[244,151 67x64] score=1,00, target=center

and highlight the checkbox for 3 seconds with a red frame

I guess in your case, the score should be 1.0 if you are looking with "checked.png" for a checked box.

So even without having tested your situation, I guess this will work in all cases (supposing in Region(r) there always is only one checkbox):

with Region(r):
    if exists(Pattern("checked.png").similar(0.9)): popup("checked")
    else: popup("unchecked")

Revision history for this message
Landy (landy-zhu) said :
#2

Thank you, RaiMan. As you said, both scores are above 0.7: one is 0.72, another is 0.98. So adjusting the similar to 0.9 can distinguish the two status. Thank you. :)

Revision history for this message
Landy (landy-zhu) said :
#3

Thanks RaiMan, that solved my question.