codeav33
codeav33

Reputation: 1

Sikuli: How to get program to capture part of the screen and store as image

So I want to capture one image, image s, which is always in the same region. It then disappears and may or may not re-appear in a different region.

I would like the program to capture the first time it appears and if it re-appears in the other region, then click a set of buttons otherwise move to a different function.

The other thing is image s changes each time the function is called but it remains in the same location.

Below is my code:

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()

I get no errors, however it doesn't seem to work. Any ideas?

Upvotes: 0

Views: 2559

Answers (2)

Tenzin
Tenzin

Reputation: 2505

To see if region1 exists in region2 you could use if region2.exists(region1) then.

Upvotes: 0

Michael Becerra
Michael Becerra

Reputation: 411

  1. I think you should change this:
    s = Screen.capture(firstRegion)
    for this:
    s = capture(firstRegion)
  2. You can get the coordinates with find(image):
    f = find(s)
    x = getX()
    y = getY()
  3. Finally, if you want to get the numer of times, you can pass a variable to the function:

    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: Sry if my english isn't good :)

Upvotes: 1

Related Questions