Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

imagesearcharea with nonzero x1 and y1 #25

Open
ghost opened this issue Oct 1, 2020 · 0 comments
Open

imagesearcharea with nonzero x1 and y1 #25

ghost opened this issue Oct 1, 2020 · 0 comments

Comments

@ghost
Copy link

ghost commented Oct 1, 2020

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

0 participants