← Back to team overview

sikuli-driver team mailing list archive

Re: [Question #152605]: I am not able to match my pattern precisely

 

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

RaiMan proposed the following answer:
Ok, I made a test on my Mac (I guess with these things there is no
difference between Mac and Windows), and I found the same results as you
had. I cannot understand why I got the previous results.

I recaptured the button images from the contained toolbar images

[code]
fillButtonEnabled = "fillButtonEnabled.png" 
fillButtonDisabled =  "fillButtonDisabled.png"

def myFind(btn, tb):
	m = toolbars[tb].find(Pattern(btn))
	m.highlight(1)
	print "Found %s on %s as %s"%(btn, tb, str(m)) 

toolbarEnabled =  "toolbarEnabled.png"
toolbarDisabled =  "toolbarDisabled.png"
	
dir = getBundlePath()
import os

toolbars = {}
# find both buttons on both toolbars
for tb in (toolbarEnabled, toolbarDisabled): 
	os.popen('open "'+os.path.join(dir, tb)+'"') # opens the toolbar image in Preview.app
	wait(2)
	toolbars[tb] = selectRegion("select " + tb)
	for btn in (fillButtonEnabled, fillButtonDisabled):
		myFind(btn, tb)
[end code]

My results:

[log] highlight Match[114,197 32x13] score=1,00, target=center for 1.0 secs 
Found fillButtonEnabled.png on toolbarEnabled.png as Match[114,197 32x13] score=1,00, target=center 

[log] highlight Match[115,197 32x13] score=1,00, target=center for 1.0 secs 
Found fillButtonDisabled.png on toolbarEnabled.png as Match[115,197 32x13] score=1,00, target=center 

[log] highlight Match[105,223 32x13] score=1,00, target=center for 1.0 secs 
Found fillButtonEnabled.png on toolbarDisabled.png as Match[105,223 32x13] score=1,00, target=center 

[log] highlight Match[106,223 32x13] score=1,00, target=center for 1.0 secs 
Found fillButtonDisabled.png on toolbarDisabled.png as Match[106,223 32x13] score=1,00, target=center

If interested in my script: https://files.me.com/rhocke/s4wkeh

Conclusion:
With Sikuli's current search implementation, you do not have a chance to find differences in your scenarios between enabled and disabled.
The reason might be, that internally the first try is done with gray scaled versions of the image to be searched and the region where to search. In your case it seems that we get a 1.0-match in all cases (I guess the brightness of the pixels does not matter).
You have to look for another way, to find out the state of the toolbar.

I think we need an additional Pattern option that makes it possible to
get different scores in such situations. I will hand this case over to
the developers and turn this question to a request bug. I know that they
are currently working on a further refinement and optimization of the
search engine to be contained in the next version. May be it fits.

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