Skip to content

imagesearcharea with nonzero x1 and y1 #25

@ghost

Description

def imagesearcharea(image, x1, y1, x2, y2, precision=0.8, im=None):
    if im is None:
        im = region_grabber(region=(x1, y1, x2, y2))
        if is_retina:
            im.thumbnail((round(im.size[0] * 0.5), round(im.size[1] * 0.5)))
        # im.save('testarea.png') usefull for debugging purposes, this will save the captured region as "testarea.png"

    img_rgb = np.array(im)
    img_gray = cv2.cvtColor(img_rgb, cv2.COLOR_BGR2GRAY)
    template = cv2.imread(image, 0)

    res = cv2.matchTemplate(img_gray, template, cv2.TM_CCOEFF_NORMED)
    min_val, max_val, min_loc, max_loc = cv2.minMaxLoc(res)
    if max_val < precision:
        return [-1, -1]
    return max_loc

so I tried to speed up the search by specifying the region with nonzero x1 and y1, which, as expected, cuts off left and top of the searched area;
this function returns the "absolute" coordinates (with reference to (0,0))

wouldn't it be better if it returned "relative" coordinates (with reference to (x1,y1))?
max_loc[0] += x1 and max_loc[1] += y1 ? (of course you cannot do that for tuples, it's just to make it clear what I mean)
especially since click_image() expects "relative" coordinates

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions