MinSimilarity setting is implemented incorrectly?

Asked by Eugene S

Hi,

I have a list of images that look very similar. In fact, when a run a loop over them, I see that the "S" parameter (similarity) is 1.00 for some of them and 0.99 for the others. It looks like that:

The code:

for x in findAll("FlagYellow.png"):
 x.highlight(1)

The screen output:

[log] highlight M[15,294 16x15]@S(0)[0,0 1280x1024] S:1.00 Center:23,301 for 1.0 secs
[log] highlight M[15,321 16x15]@S(0)[0,0 1280x1024] S:1.00 Center:23,328 for 1.0 secs
[log] highlight M[15,375 16x15]@S(0)[0,0 1280x1024] S:1.00 Center:23,382 for 1.0 secs
[log] highlight M[15,542 16x15]@S(0)[0,0 1280x1024] S:0.99 Center:23,549 for 1.0 secs
[log] highlight M[15,402 16x15]@S(0)[0,0 1280x1024] S:0.99 Center:23,409 for 1.0 secs
[log] highlight M[15,402 16x15]@S(0)[0,0 1280x1024] S:0.98 Center:23,409 for 1.0 secs

Now, when I set the Settings.MinSimilarity parameter to "1.00", the iteration goes just through some of the objects(not all of them) that used to have 1.00 similarity (at least according to the log on the screen).

However, when I set the parameter to be "0.99", it iterates through ALL the objects with similarity "1.00" but does not iterate over the objects with similarity "0.99". This is actually exactly what I am looking for but it doesn't seem right.

Is that just me or maybe that's a bug?

Regards,
Eugene

Question information

Language:
English Edit question
Status:
Solved
For:
SikuliX Edit question
Assignee:
No assignee Edit question
Solved by:
Eugene S
Solved:
Last query:
Last reply:
Revision history for this message
RaiMan (raimund-hocke) said :
#1

Which version of Sikuli?

Revision history for this message
Eugene S (shragovich) said :
#2

Sorry, forgot to mention.
This is 1.0.1.

Thanks,
Eugene

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

ok, I will check it later.

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

I am just busy with moving the OpenCV related features (find, findAll, onChange, ...), the related Java classes like Finder and the functions implemented on the C++ level completely to the Java level, which is possible now, since OpenCV 2.4.5+ has the option to generate a Java OpenCV API layer and the performance is the same.
So I will revise this similarity handling anyway to be consistent all over the place.

current situation with 1.0.1:
- internally similarity score from OpenCV match is a float number and this is never 1.0 or 0.0 exactly.
- What you see with the highlight message is a rounded number (s>0.9950000000.... is 1.00 and 0.9850000000... < s <0.995 is 0.99)
- the way, how the MinSimilarity setting is used internally is different for find() and findAll()

Recommendation:
Never use MinSimilarity as 1.0, always use a value <1.0 (usually 0.99 for exact matches is sufficient - but feel free to try other values with more digits like 0.9999999).
The implementation of the Pattern class already assures this internally (exact() evaluates to 0.99).

Revision history for this message
Eugene S (shragovich) said :
#5

Hi RaiMan,

Thanks a lot for your answer and the explanation. This is very valuable!

I'd like to have your opinion on a certain issue I am experiencing with regards to MinSimilarity.

I have automated a certain process. To verify that this process was completed successfully, I have to verify that a certain icon color was changed. This is the only indication that the process is complete. I was searching through the launchpad questions for a way to detect colors using Sikuli but it doesn't seem like a trivial task.

That's when I tried to iterate through all the appearances of an image on the screen (both colors) using the same image pattern. I have noticed that the images of the same color like the pattern image I was using, are detected with similarity=1.00 and those of the other colors were detected with similarity=0.99. So I thought I can exploit that fact to distinguish between the two images.

Do you think it's a possible strategy in my situation? Can I even somehow access the detected image object similarity field? I mean, just to programatically check what's the detected image similarity parameter?

Hope I have described my issue clear. :)

Thanks again!
Eugene S

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

Yes it is.

To get the similarity score:
m = find(button)
print m.getScore()

Revision history for this message
Eugene S (shragovich) said :
#7

Yes, that's it!

Thanks a lot RaiMan.
Appreciate that!