← Back to team overview

sikuli-driver team mailing list archive

[Question #247612]: function to return the region between two other regions

 

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

hello,

i sometimes find myself wanting to search for an image between two other images so i made a function that returns a region between two other regions (sort of like an intersection, but i guess not quite). if the input regions overlap it returns the overlapping region. it works well enough but it requires two calls to find, so it only takes patterns as input. i would eventually like it to accept any combination of 2 patterns, matchs, regions or locations just like the native sikuli functions (minus string i guess, because i don't really understand how that input type works).

i looked up createUnion and createIntersection from java.awt.Rectangle but they dont seem quite the same, although im not familiar with java. 

anyway, here it is. feedback would be cool.

def between(img1, img2):
    '''
        returns the region between two given images.
        if the images overlap, returns the overlapping region.
    '''
    r1 = find(img1)
    r2 = find(img2)
    leftBoundary = max(r1.getX(), r2.getX())
    rightBoundary = min(r1.getTopRight().getX(), r2.getTopRight().getX())
    topBoundary = max(r1.getY(), r2.getY())
    bottomBoundary = min(r1.getBottomRight().getY(), r2.getBottomRight().getY())
    x_coord = min(leftBoundary, rightBoundary)
    y_coord = min(topBoundary, bottomBoundary)
    w = abs(leftBoundary - rightBoundary)
    h = abs(topBoundary - bottomBoundary)
    print 'leftBoundary: ', leftBoundary
    print 'rightBoundary: ', rightBoundary
    print 'topBoundary: ', topBoundary
    print 'bottomBoundary:', bottomBoundary
    print 'x: %s\ny: %s\n w: %s\n h: %s' % (x_coord, y_coord, w, h)
    return Region(x_coord, y_coord, w, h)

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