图像类不断选择不同的图像而不是相同,如何修复? Sikuli

时间:2016-09-20 23:06:44

标签: python jython sikuli

我使用随机5卡洗牌器来获取一些基本脚本,但脚本将选择A A 3或10 9 8而不是忽略它们。我怎么能让它跑得更快?

running = True

def runHotkey(event):
    global running
    running = False

Env.addHotkey(Key.F1, KeyModifier.CTRL, runHotkey)

while exists("1474199877323.png")and running:
    click(Pattern("1474369588947.png").similar(0.80))
    wait(2)
    click("1474138615993.png")
    click("1474138629993.png")
    wait(1)
    imageCount=0
    images = []
    # find all images and store them in a list to prevent additional search
    if exists(Pattern("1474368132347.png").similar(0.90)):
            for image in findAll(Pattern("1474368132347.png").similar(0.89)):  
            wait(1)
            images.append(image)
            #check list length and act accordingly
        if len(images) >= 2:
            wait(1)
            for image in images:
                wait(1)
                image.click()
            click(Pattern("1474409820809.png").similar(0.93))


if exists(Pattern("1474409495397.png").similar(0.91)):
        for image1 in findAll(Pattern("1474409495397.png").similar(0.91)):
            wait(1)
            images.append(image1)
            #check list length and act accordingly
        if len(images) >= 3:
            wait(1)
            for image1 in images:
                wait(1)
                image1.click()
            click(Pattern("1474369529687.png").similar(0.90))

if exists(Pattern("1474410728933.png").similar(0.95)):
        for image2 in findAll(Pattern("1474410728933.png").similar(0.95)):
            wait(1)
            images.append(image2)
            #check list length and act accordingly
        if len(images) >= 3:
            wait(1)
            for image2 in images:
                wait(1)
                image2.click()
            click(Pattern("1474369529687.png").similar(0.90))  

if exists(Pattern("1474411088984.png").similar(0.91)):
        for image3 in findAll(Pattern("1474411088984.png").similar(0.91)):  
            wait(1)
            images.append(image3)
            #check list length and act accordingly
        if len(images) >= 3:
            wait(1)
            for image3 in images:
                wait(1)
                image3.click()
            click(Pattern("1474409820809.png").similar(0.93))


if exists(Pattern("1474411136494.png").similar(0.93)):        
        for image4 in findAll(Pattern("1474411136494.png").similar(0.93)):
            wait(1)
            images.append(image4)
            #check list length and act accordingly
        if len(images) >= 3:
            wait(1)
            for image4 in images:
                wait(1)
                image4.click()
            click(Pattern("1474369529687.png").similar(0.90))

if exists(Pattern("1474411200166.png").similar(0.94)):        
        for image5 in findAll(Pattern("1474411200166.png").similar(0.94)):
            wait(1)
            images.append(image5)
            #check list length and act accordingly
        if len(images) >= 3:
            wait(1)
            for image5 in images:
                wait(1)
                image5.click()
            click(Pattern("1474369529687.png").similar(0.90))    

if exists(Pattern("1474411297233.png").similar(0.94)):        
        for image6 in findAll(Pattern("1474411297233.png").similar(0.94)):  
            wait(1)
            images.append(image6)
            #check list length and act accordingly
        if len(images) >= 3:
            wait(1)
            for image6 in images:
                wait(1)
                image6.click()
            click(Pattern("1474409820809.png").similar(0.93))


if exists(Pattern("1474411373675.png").similar(0.94)):                    
        for image7 in findAll(Pattern("1474411373675.png").similar(0.94)):
            wait(1)
            images.append(image7)
            #check list length and act accordingly
        if len(images) >= 3:
            wait(1)
            for image7 in images:
                wait(1)
                image7.click()
            click(Pattern("1474369529687.png").similar(0.90))

if exists(Pattern("1474411438209.png").similar(0.92)):                    
        for image8 in findAll(Pattern("1474411438209.png").similar(0.92)):
            wait(1)
            images.append(image8)
            #check list length and act accordingly
        if len(images) >= 3:
            wait(1)
            for image8 in images:
                wait(1)
                image8.click()
            click(Pattern("1474369529687.png").similar(0.90))  

if exists(Pattern("1474411516981.png").similar(0.95)):        
        for image9 in findAll(Pattern("1474411516981.png").similar(0.95)):  
            wait(1)
            images.append(image9)
            #check list length and act accordingly
        if len(images) >= 3:
            wait(1)
            for image9 in images:
                wait(1)
                image9.click()
            click(Pattern("1474409820809.png").similar(0.93))                 

if exists(Pattern("1474411592794.png").similar(0.92)):                    
        for imagea in findAll(Pattern("1474411592794.png").similar(0.92)):
            wait(1)
            images.append(imagea)
            #check list length and act accordingly
        if len(images) >= 3:
            wait(1)
            for imagea in images:
                wait(1)
                imagea.click()
            click(Pattern("1474369529687.png").similar(0.90))

if exists(Pattern("1474411644943.png").similar(0.90)):                    
        for imageb in findAll(Pattern("1474411644943.png").similar(0.90)):
            wait(1)
            images.append(imageb)
            #check list length and act accordingly
        if len(images) >= 3:
            wait(1)
            for imageb in images:
                wait(1)
                imageb.click()
            click(Pattern("1474369529687.png").similar(0.90))  

if exists(Pattern("1474411713586.png").similar(0.90)):                    
        for imagec in findAll(Pattern("1474411713586.png").similar(0.90)):
            wait(1)
            images.append(imagec)
            #check list length and act accordingly
        if len(images) >= 3:
            wait(1)
            for imagec in images:
                wait(1)
                imagec.click()
            click(Pattern("1474369529687.png").similar(0.90))                       
else:
    wait(0)

1 个答案:

答案 0 :(得分:0)

如果在给定的相似度下给定图像有多个匹配,则sikuli仅从中单击一个图像(随机)。因此,如果您想更稳定地点击相似图像,则需要使用findAll函数开发代码,然后对findAll函数的Match结果进行排序,然后单击其中一个。您可以根据findAll之后找到的匹配对象的坐标对图像进行排序,并在排序后单击其中一个图像。

如果要处理(单击)每个找到的匹配,直接遍历findAll的所有输出结果并执行操作。在这种情况下无需进行排序。