【问题标题】:Sikuli: How to get program to capture part of the screen and store as imageSikuli:如何获取程序以捕获部分屏幕并存储为图像
【发布时间】:2016-01-02 17:52:24
【问题描述】:

所以我想捕捉一个图像,image s,它总是在同一个区域。然后它会消失,并且可能会或可能不会重新出现在不同的区域。

我希望程序在它第一次出现时捕捉它,如果它再次出现在其他区域,然后单击一组按钮,否则移动到不同的功能。

另一件事是每次调用函数时 image 都会发生变化,但它仍然在同一位置。

下面是我的代码:

def playLoop():

s = capture(firstRegion)
warnBox = exists("1443867801301.png")
if not warnBox:
    if exists("1443867813008.png"):
        click(x)
        playLoop()
    else:
        if secondRegion.exists(Pattern(s).similar(0.8)):
            wait(3)
            click(x)
            playLoop()
        else:
            loopLoop()
else:
    doubleClick(y)
    if secondRegion.exists(Pattern(s).similar(0.8)):
            wait(3)
            click(x)
            playLoop()
    else:            
        loopLoop()

我没有收到任何错误,但它似乎不起作用。有什么想法吗?

【问题讨论】:

  • 我认为您的程序在给定图像有机会出现在另一个区域之前已经完成。看看while not exists

标签: python sikuli sikuli-script sikuli-ide


【解决方案1】:
  1. 我认为你应该改变这个:
    s = Screen.capture(firstRegion)
    为此:
    s = 捕获(第一个区域)
  2. 您可以使用 find(image) 获取坐标:
    f = 查找
    x = getX()
    y = getY()
  3. 最后,如果要获取次数,可以给函数传递一个变量:

    def playLoop(times,x,y):
    
        s = capture(firstRegion)
        t = find(s)
        if times==0:
            warnBox = exists("1443867801301.png")
            if not warnBox:
                if exists("1443867813008.png"):
                    click(x)
                    times+=1
                    playLoop(times,t.getX(),t.getY())
        if times != 0:
            warnBox = exists("1443867801301.png")
            if not warnBox:
                if t.getX() != x or t.getY() != y: #different location
                    doSomething()
                else:
                    otherFunction() #same location
                times+=1
    

    PD:对不起,如果我的英语不好:)

【讨论】:

  • 我已经听从了你的第一个建议,但是我对获取坐标并不感兴趣。我想要的只是捕获第一个区域的功能,然后在需要时查看捕获的图像是否存在于第二个区域中。我已经更新了我的代码和问题。不过感谢您的帮助:)
【解决方案2】:

要查看 region1 是否存在于 region2 中,您可以使用 if region2.exists(region1) then

【讨论】:

    猜你喜欢
    • 2012-08-22
    • 1970-01-01
    • 2015-12-18
    • 2010-10-17
    • 1970-01-01
    • 2012-03-20
    • 2021-05-31
    • 2016-02-13
    • 2018-05-21
    相关资源
    最近更新 更多