Search code examples
javaautomationsikuli

Sikuli can't tell colors apart


I'm developing a program with Java and Sikuli and I want to click on a red image with a specific shape that is located on screen. The problem is that on the screen there is another image with that same shape but different color, blue.

import org.sikuli.script.Screen;

this.screen.type("C:\\Images\\TestImage.png", "a"); // this is what I'm using.

My mouse keeps moving between the two images because it can't tell the difference in color.


Solution

  • There is no way Sikuli can make the right choice for you. It can only locate a matching are based on your pattern (color in this case). To work around this issue you should provide some reference points that are unique and can be used to "help" Sikuli find the right match. For example, if the pattern you are interested in is located at the left side of the screen, then you can limit the search to the left side of the screen only. Or if you have a unique visual object in the are of interested you can use it as a pivot and look only around it.

    On top of that, if you have few similar items appear in some ordered fashion (one under another for example), you can let Sikuli find all of them, calculate their coordinates and select the object you need based on these coordinates.