简体   繁体   English

如何使用Java在Sikuli中找到图像的精确匹配

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

Am new to Sikuli and trying to Automate Citirx Application. 是Sikuli的新手,它正在尝试使Citirx应用程序自动化。 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 在第二张图片中,我突出显示了我需要选择红色的角色

在此处输入图片说明 在此处输入图片说明

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;
       }
      }

The image recognision uses per default a similarity of 0.7 (see description of Patterns in SikuliX Documentation ). 图像识别默认使用0.7的相似度(请参阅SikuliX文档中的Patterns描述 )。 That means SikuliX looks for 'pretty similar' images. 这意味着SikuliX会寻找“非常相似”的图像。 You can specify the similarity for the pattern recognision thanks to the method similar , or in your case use the method exact . 您可以使用相似的方法来指定模式识别的similar ,或者在您的情况下使用exact方法。 In your method clipExist , you should replace the name of the image: 在方法clipExist ,应替换图像的名称:

    Match m = screen.exists(clip);

by: 通过:

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

It seems SikuliX 1.1 experience some problem with finding the text on a screen, but recognition works. SikuliX 1.1似乎在屏幕上查找文本时遇到一些问题,但是识别有效。 You might want to scan the entire text screen by screen and split the lines. 您可能希望逐个屏幕扫描整个文本屏幕并拆分行。 Next compare each line with the required role and save the degree of similarity. 接下来,将每行与所需角色进行比较,并保存相似度。 Select the line with the biggest similarity. 选择相似度最大的行。 In Python/Jython exists a special function for that in difflib module. 在python / Jython中,difflib模块中有一个特殊的函数。 similarity = difflib.SequenceMatcher(None, string_a, string_b)

Here are the alternatives that you can do. 这是您可以做的选择。

First alternative: capture scrollbar 第一种选择:捕获滚动条

  1. Capture the down arrow in the scrollbar 捕获滚动​​条中的向下箭头
  2. Capture the image when you reach the end of scrollbar. 到达滚动条的末尾时捕获图像。 The image contains the scroll progress and the down arrow of the scrollbar 该图像包含滚动进度和滚动条的向下箭头
  3. Click down arrow until you find image of (2) 单击向下箭头,直到找到(2)的图像

This method have drawback ie when the number of items are dynamic, the visual appearance of (2) will be different especially the scroll progress. 该方法具有缺点,即当项目数是动态的时,(2)的视觉外观将不同,尤其是滚动进度。 However, this can be tricked by capturing only the lower part of scroll progress and the arrow. 但是,这可以通过仅捕获滚动进度和箭头的下部来欺骗。 Please note that your mouse may make difficulty in (3) because you may not find (2) when it is covered by mouse. 请注意,您的鼠标可能会在(3)中遇到困难,因为在被鼠标覆盖时可能找不到(2)。 To handle this, every time you click down arrow, you may hover your mouse a bit before checking for (2). 要解决此问题,每次单击向下箭头时,在检查(2)之前都可以将鼠标悬停一点。 This is the complete script: 这是完整的脚本:

down_arrow = "downarrow.png"
complete_scroll = "completescroll.png"

while not exists(complete_scroll):
    click(down_arrow)
    hover(Location(300, 200))

Second alternative, use keyboard (down key) 第二种选择,使用键盘(向下键)

Click anywhere in the items to be scrolled and do some type(Key.DOWN) for the number of item you have. 在要滚动的项目中的任意位置单击,然后对您拥有的项目数进行一些键入(Key.DOWN)。 In case you have dynamic number of item, you may do type(Key.DOWN) for any number that always bigger than your number of items. 如果您有动态的项目数,则可以键入(Key.DOWN)表示总是大于项目数的任何数字。 Here is the script to do 这是要做的脚本

inside_item = "inside.png"

for n in range(10000):
    type(Key.DOWN)

Hope it helps 希望能帮助到你

I used 's' as a screen class reference. 我使用“ s”作为屏幕类参考。 Hence, once we get an image then we will set the region for the same followed by the required image where you want to click 因此,一旦获得图像,我们将为该区域设置相同的区域,然后是您要单击的所需图像

public static void main(String args[])
{
    Match m = s.find("IMAGE");
    Region r = new Region(m.x+11, m.y+22,12,12);
    r.click(); 
    s.find("ENTPIMAGE.PNG");
    r.click("ENTPIMAGE.PNG");
}  

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM