← Back to team overview

sikuli-driver team mailing list archive

Re: [Question #247612]: function to return the region between two images

 

Question #247612 on Sikuli changed:
https://answers.launchpad.net/sikuli/+question/247612

    Status: Open => Answered

RaiMan proposed the following answer:
This is a solution, that works with 1.0.1+

def between(item1, item2):
    regs = [None, None]
    ix = 0
    for item in (item1, item2):    
        if isinstance(item, str) or isinstance(item, Pattern):
            if exists(item):
                regs[ix] = Region(getLastMatch())
        elif isinstance(item, Region) or isinstance(item, Match):
            regs[ix] = Region(item)
        elif isinstance(item, Location):
            regs[ix] = item.grow(1)
        ix += 1
    if None in regs:
        return None
    # now we have 2 valid regions
    # sort them with respect to x of top left
    # for further more sophisticated evals
    regs = sorted(regs, key=lambda reg: reg.x)
    # we now simply return the union region containing both regions
    # what really means "between" has to be defined more clearly
    return regs[0].add(regs[1])

it accepts Image, Pattern, Region, Match or Location for both parameters.
Image or Pattern are first searched on the whole screen.
Both items must be on the same screen.

Returns None, if there is a problem with one of the given parameters.

Returns the region, that contains both given items.

11133333333333333
11133333333333333
11133333333333222
33333333333333222
33333333333333222

1 the pixels of the one region
2 the pixels of the other region
3 additional pixels that belong to the resulting region

-- 
You received this question notification because you are a member of
Sikuli Drivers, which is an answer contact for Sikuli.