How to set Finder similarity

Asked by Chengpu Wang

I am using the latest 64-bit Sikuli IDE on 64-bit Win7. It seems that Finder always uses exact find, ignoring my similarity setting in Finder.find(). To demonstrate this, I have my captured.png file displayed 1x1 on the screen and run the following simple script:

finder = Finder( "captured.png" )
finder.find( "captured.png", 0.7 )
if not finder.hasNext():
    print( 'Can not find the orginal image itself by Finder' )
finder.find( "target.png", 0.7 )
if not finder.hasNext():
    print( 'Can not find the target image by Finder' )
if not exists( "target.png" ):
    print( 'Can not find the target image on screen' )

The result is:

Can not find the target image by Finder

In another word, the target.png can be found on screen, but not in the capture.png. The capture.png can find itself.

What have I done wrong?

Question information

Language:
English Edit question
Status:
Answered
For:
SikuliX Edit question
Assignee:
No assignee Edit question
Last query:
Last reply:
Revision history for this message
Chengpu Wang (chengpu) said :
#1

Anyway I can send you the two png files?

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

finder.find( "captured.png", 0.7 )

should give an error !? Not a valid function call.

finder.find( Pattern("captured.png").similar(0.95))

a similarity of below 0.8 does not make sense (the default is 0,7 which may lead to false positives with "bad" shots in some cases)

If you want an exact match use Pattern().exact() which means >0.99

Revision history for this message
Chengpu Wang (chengpu) said :
#3

No, my script runs fine. No I DO NOT want exact match.

Here is the API spec at http://doc.sikuli.org/finder.html:
class Finder
  find(path-to-imagefile[, similarity])
  Find a given image within a source image previously specified in the constructor of the finder object.
  Parameters:
  path-to-imagefile – the target image to search for
  similarity – the minimum similarity a match should have. If omitted, the default is used.

I changed to what you have suggested:

finder.find( Pattern("target.png").similar(0.61) )
if not finder.hasNext():
    print( 'Can not find the target image by Finder' )

The result is the same:
Can not find the target image by Finder

Revision history for this message
Chengpu Wang (chengpu) said :
#4

Looks to me like Finder can ONLY do exact match, no matter how you call it.

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

-- Looks to me like Finder can ONLY do exact match, no matter how you call it.
no not at all.
The Finder class internally is used for all search ops.

-- docs say: find(path-to-imagefile[, similarity])
ok, makes sense for that usage (Though I did never use that ;-)

-- Finder does not work
f = Finder(some_image)
f.find(some_other_image)

some_image must have both width and height equal or greater compared to the respective values of some_other_image.

You might check using the IDE:
- display some_image with some image viewer in original size
- check using IDE Preview

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

BTW: you can send me what you want silently to my mail at https://launchpad.net/~raimund-hocke

Revision history for this message
Chengpu Wang (chengpu) said :
#7

Thanks, message sent.

The captured.png is larger than target.png in both dimensions. The match of target.png in captured.png is about 0.85 using "Matching Preview".

Please see if you can reproduce my problem on your end.

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

I checked your example with version 1.0.1 and indeed found a strange behavior:
Everything works as expected, but using Finder() directly with the captured image reports a similarity score of 0.57, whereas having the image displayed on the screen with a viewer and using normal screen find op Sikuli reports a similarity score of 0.88.

I have to check this the next time with version 1.1 (currently I have no idea about a possible reason).

I will convert your question to a bug. Thanks for finding.

Can you help with this problem?

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

To post a message you must log in.