【问题标题】:Sikuli Check multiple of the same images on screenSikuli 检查屏幕上的多个相同图像
【发布时间】:2018-12-26 13:19:44
【问题描述】:

我可以使用exists()检查图像是否存在

但我想知道是否可以检查同一图像是否多次出现在屏幕上,例如:

如果点击按钮后球存在...

如果一个球在屏幕上出现两次,请单击另一个按钮...有什么想法吗?

【问题讨论】:

    标签: sikuli


    【解决方案1】:

    您也可以使用 Python 的列表推导来做到这一点:

    imageCount = len(list([x for x in findAll(image)]))
    
    #the rest is like @Eugene's answer
    if imageCount == 1:
        click(buttonA)
    elif imageCount == 2:
        click(buttonB)
    else:
        pass
    

    【讨论】:

      【解决方案2】:

      要检查屏幕上出现的所有图像,请使用以下方法,添加额外的单击以确认图像的确切位置。

      代码:

      Screen s = new Screen();
      Iterator<Match> it = s.findAll(Imagepath);
      
      while(it.hasNext()){
          System.out.println("the match is "+it.next().click());
      }
      

      或者你可以找到迭代器的长度。

      【讨论】:

        【解决方案3】:

        您可以使用 Sikuli Region 类的findAll method。示例代码如下所示:

        def returnImageCount(image):
            count = 0
            for i in findAll(image):
                count += 1
            return count
        
        imageCount = returnImageCount(image)
        
        if imageCount == 1:
            click(buttonX.image)
        elif imageCount == 2:
            click(buttonY.image)
        else:
            pass
        

        【讨论】:

          【解决方案4】:

          使用 Region 对象的 findall 方法。它为您提供所有匹配图像/图案的列表。 Sikuli 文档有很好的使用细节。参考这里http://doc.sikuli.org/region.html#Region.findAll

          【讨论】:

            【解决方案5】:

            如果您想计算窗口上某个图像的数量,您可以使用:

            Image1 = ("Image1.png")
            ImagesFound = list(findAll(Image1))
            numberFound = len(ImagesFound)
            print(numberFound)
            

            如果您想在最前面的窗口(例如弹出窗口)上计算某个图像的数量。
            你可以使用:

            Image1 = ("Image1.png")
            appWindow = App.focusedWindow()
            ImagesFound = list(appWindow.findAll(Image1))
            numberFound = len(ImagesFound)
            print(numberFound)
            

            【讨论】:

              猜你喜欢
              • 1970-01-01
              • 2017-09-20
              • 1970-01-01
              • 2019-12-10
              • 2020-03-05
              • 2016-11-06
              • 2014-12-05
              • 2012-11-28
              • 2013-08-08
              相关资源
              最近更新 更多