Sikuli Check multiple of the same images on screen

我只是一个虾纸丫 提交于 2019-12-11 06:59:43

问题


I can check if the image exist with exists()

But i want to know if i can check if the same image appears more than once appearing on the screen, for example:

if a ball exists once click a button...

if a ball exists twice on screen click another button... any ideas?


回答1:


You can use findAll method from Sikuli Region class. The example code will look like this:

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



回答2:


You can also use Python's list comprehension to do it:

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



回答3:


To check all the occurrences of an Image on the screen use the below, additional click is added to get the confirmation of the image exact location.

code:

Screen s = new Screen();
Iterator<Match> it = s.findAll(Imagepath);

while(it.hasNext()){
    System.out.println("the match is "+it.next().click());
}

Or you can find the length of the iterator.




回答4:


Use findall method of Region object. It gives you a list of all matching image/pattern. Sikuli documentation has good details on usage. Refer here http://doc.sikuli.org/region.html#Region.findAll




回答5:


If you would like to count the number of a certain image on the window you could use:

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

And if you would like to count the number of a certain image on the most front window, like a pop-up.
You could use:

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


来源:https://stackoverflow.com/questions/19614405/sikuli-check-multiple-of-the-same-images-on-screen

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!