Same image with different colors are the same for Sikuli

Asked by Deses

Hello and congratulations for this excellent piece of work.

Screen A: http://dl.dropbox.com/u/2240774/A.png
Screen B: http://dl.dropbox.com/u/2240774/B.png

Well, I have a problem trying to automate a game, when it comes to tell if screenshot A exists, no matter how far I set the slider to tune the similarity, it always thinks that it's screenshot B.

I don't have to click on the image, only find if it exists, but as far as I know, Sikuli doesn't discriminate between colors. Ohter users had similar problems.

There is something I can do, or do you have any tip for me to fix that?

Thanks!!

If interested, I have the full screenshots:

A full: http://dl.dropbox.com/u/2240774/A%20full.png
B full: http://dl.dropbox.com/u/2240774/B%20full.png

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:

This question was reopened

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

Tested on my Mac Lion with your images.

I confirm, that both images in both cases give the same score. So the normal features of Sikuli will not help you.

This is the easiest workaround:

from java.awt import Robot

imgA = "A.png"

m = find(imgA)
cp = m.getTopLeft().offset(5,5) # select a pixel, that has the background color
r = Robot()
c = r.getPixelColor(cp.x, cp.y) # get the color object
crgb = ( c.getRed(), c.getGreen(), c.getBlue() ) # decode to RGB values
print crgb

you will get a different color value in both cases, which makes it possible to decide with one is present.

background:
--- http://docs.oracle.com/javase/6/docs/api/java/awt/Robot.html
--- http://docs.oracle.com/javase/6/docs/api/java/awt/Color.html

Revision history for this message
Deses (deses12) said :
#2

Oh my, that was really fast. (I just woke up xD)

I've tryed your code and at first it couldn't found the Robot method, but then I realized that I didn't imported the class... I'm still asleep. Hehe

Well, this solves my question.

Thanks a lot! You are awesome. :D

Revision history for this message
Deses (deses12) said :
#3

Hmm, how do I compare between crgb (or c) and a fixed variable?

gris = (176, 160, 125)

if crgb == gris:
    do things

Is that correct?

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

Yes.

Revision history for this message
Deses (deses12) said :
#5

Thanks, this is solved. :D

Revision history for this message
Deses (deses12) said :
#6

Thanks RaiMan, that solved my question.

Revision history for this message
Katy (katymagowan) said :
#7

This helped me a lot! Thanks RaiMan