RaiMan / SikuliX-2014

SikuliX version 1.1.2 (until February 2018)
http://sikulix.com
806 stars 234 forks source link

False positive when do Region.exists() again with increased similarity --- fixed 2016-10-23 #231

Closed ubershy closed 7 years ago

ubershy commented 7 years ago

If I'm not mistaken, the problem exists since the old sikulixapi 1.1.0 to the current sikulixapi 1.1.1-SNAPSHOT.

What happens:

When using sikulixapi as library in Java project, after the first successful find with Region.exists() using low similarity parameter, knowing that it will fail with high similarity, all subsequent tries to find with higher similarity in the same conditions will be successful (false positive).

How to easily reproduce:

// Create a region.
Region region= new Region(100, 100, 100, 100);
// Define path to target image file.
// Such image file should not be recognizable with high similarity parameter,
// but recognizable with low similarity.
Sting imagePath = "somefile.png";
// Statement below equals null.
// It has not found image, because of very high Similarity parameter.
// Working correctly.
region.exists(new Pattern(imagePath).similar(1.00), 0); 
// Statement below is not equal to null.
// It has found image, because of very low Similarity parameter.
// Working correctly.
region.exists(new Pattern(imagePath).similar(0.01), 0);
// Surprisingly the statement below is not equal to null.
// It has found image, because internally sikulixapi uses previous Similarity
// parameter for "somefile.png" instead of new high Similarity.
// Not working correctly.
region.exists(new Pattern(imagePath).similar(1.00), 0);

Possible culpit:

This line which incorrectly defines "score" variable, which is Similarity parameter. The "score" variable is later used in these places: Place 1 Place 2

Possible solution (I'm not sure):

Replace this line: float score = (float) (img.getLastSeenScore() - 0.01); To this line: float score = (float) (ptn.getSimilar() - 0.01);

Note: this report is not a duplicate of issue #190

By the way, thank you, @RaiMan , for maintaining SikuliX. =)

RaiMan commented 7 years ago

Thanks for the info. I will check.

RaiMan commented 7 years ago

I have fixed it. Thanks again for finding. New nightly available in about 2 hours.

ubershy commented 7 years ago

Wow, so fast! Thank you. =)

RaiMan commented 7 years ago

@ubershy Was obvious and easy to fix. The rest is semi-automatic workflow ;-) all the best