How to Find Exact match of an Image in Sikuli with Java

Satish Dhanaraj picture Satish Dhanaraj · Nov 20, 2015 · Viewed 10.2k times · Source

Am new to Sikuli and trying to Automate Citirx Application. Need Help

Am trying to select a user role in a screen, The screen has multiple roles and hence i need to scroll down the screen and search for a particular Role and click the Role.

I have Captured image of a Particular Role that i need to select and used below Code. In the second Image i have highlighted the Role i need to select in Red

enter image description here enter image description here

Below is the Code an Trying:

Creating a Method:

 public static boolean clipExist(Screen screen, String clip )
 {
        Match m = screen.exists(clip);
         if(m != null)
      {
              return true;
        }
       else
       {
          return false;
       }
   }

Using the Method:

        while(! clipExist(screen, "C:\\Users\\Satish_D1\\workspace\\Sikuli Demo\\Images\\DownArrow.PNG"))       
    {           
       screen.wheel(1 , 3);     
       if(clipExist(screen, "C:\\Users\\Satish_D1\\workspace\\Sikuli Demo\\Images\\Roles\\UK\\ENTP\\GEDIS_SALES_SUPPORT_ORL_CPF2.0_UK_ENTP.PNG"))
       {
        screen.doubleClick("C:\\Users\\Satish_D1\\workspace\\Sikuli Demo\\Images\\Roles\\UK\\ENTP\\GEDIS_SALES_SUPPORT_ORL_CPF2.0_UK_ENTP.PNG",0);
        break;
       }
      }

Answer

Loic Mouchard picture Loic Mouchard · Feb 22, 2016

The image recognision uses per default a similarity of 0.7 (see description of Patterns in SikuliX Documentation). That means SikuliX looks for 'pretty similar' images. You can specify the similarity for the pattern recognision thanks to the method similar, or in your case use the method exact. In your method clipExist, you should replace the name of the image:

    Match m = screen.exists(clip);

by:

    Match m = screen.exists(Pattern(clip).exact())