Any possiblity that Sikuli can recognise colors too (Same image with different colors) ?

Asked by Anshu

So what i need in my application is to draw some lines of different colors , picking the color icon , from a toolbar.
There are different images for each color - which are exactly same in size and shape except the colors(red/blue/green)
When i capture those images and try to click on those - Sikuli woul dclick on any of those (usually the firs one) for all the colors .

 Is there a way - Sikuli can recognize the exact image based on color difference only?

Thanks
Anshu

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

trying to click() on each color element using an image will not work. It is a known problem, that shapes that only differ in color might not be found correctly, if Sikuli has the "choice" (more than one element currently on screen).

I suppose, that the color picker is a fixed element. I usually solve this kind of problem this way:
- somehow get the position of the whole color picker
- calculate the offset of the needed click points relative to the color picker

example:
m = find(<image of color picker>)
red = m.getCenter().left(50)
blue = m.getCenter().right(20)
#.... and more as needed
click(red) # would select red color

The offsets can be measured using the Preview window and manually taken into the script.

Alternatively you can make a Pattern with a target offset for each element, but I always try to minimize find operations:
red = Pattern(<image of color picker>).targetOffset(-50,0)
blue = Pattern(<image of color picker>).targetOffset(20,0)
#.... and more as needed
click(red) # would select red color

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

trying to click() on each color element using an image will not work. It is a known problem, that shapes that only differ in color might not be found correctly, if Sikuli has the "choice" (more than one element currently on screen).

I suppose, that the color picker is a fixed element. I usually solve this kind of problem this way:
- somehow get the position of the whole color picker
- calculate the offset of the needed click points relative to the color picker

example:
m = find(<image of color picker>)
red = m.getCenter().left(50)
blue = m.getCenter().right(20)
#.... and more as needed
click(red) # would select red color

The offsets can be measured using the Preview window and manually taken into the script.

Alternatively you can make a Pattern with a target offset for each element, but I always try to minimize find operations:
red = Pattern(<image of color picker>).targetOffset(-50,0)
blue = Pattern(<image of color picker>).targetOffset(20,0)
#.... and more as needed
click(red) # would select red color

Revision history for this message
Tsung-Hsiang Chang (vgod) said :
#3

Setting the similarity to 1.0 may work if the color icons are not pure solid color block.

Revision history for this message
Anshu (anshu-ca) said :
#4

Thanks RaiMan, that solved my question.

Revision history for this message
Anshu (anshu-ca) said :
#5

Chang, similarity 1.0 did work when with a testing script on my MAC .But in my test suite - i am using the same image against XP,Win7 and MAC 10.6 - so there is a risk that at 1.0 it might not work on all Oses , for same script and same image.

But this does seem a solution for other cases, when i have different images for each OS.

Thanks
Anshu

Revision history for this message
Albert (servant76) said :
#6

I am trying to create a sikuli script (which runs in a JUNIT test) to differentiate between a button with a grey background vs a button with a blue background (the size of the button and text on it are the same).

Setting the MinSimilarity to 1.0 doesn't seem to work.

Any ideas on how to get the test to fail when the button is grey when it should be blue?

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

@Albert
You should subscribe to the question (did it for you), if you ask something in a comment.

--- minSim 1.0
I still recommend to use 0.99, if you mean "exact match", since there are some situations, where 1.0 and exact() do not work at all or even crash the script.

--- differentiate between a button with a grey background vs a button with a blue background
if .similar(0.99) does not help, the only possibility currently is to use the "color picker" of Java Robot to additionally check the color of a pixel after finding the button.

for an approach see: https://answers.launchpad.net/sikuli/+question/176332