How to get the pixel location of an image from cv2 matchTemplate result

In python I am importing mss to capture my screen, numpy to process the screen grab, cv2 to matchTemplate an image from the screen grab, and pyagutogui to control my mouse.

Below is code that takes a screenshot and if there is a match to an image with >85% accuracy it draws a bounding box around it.

This works fine. However, instead of showing the screen grab, I want to just click on the location of the matchTemplate on my screen. And in the code below I believe I am telling my mouse to move to a location in my numpy array??

My Question: How do I convert image location in my cv2.matchTemplate to image location on my computer screen?

import cv2
import numpy as np
import pyautogui as pg
import mss

sct = mss.mss()
screen_grab_dimensions = {
    'left': 0,
    'top': 0,
    'width': 750,
    'height': 500
}
img = cv2.imread('img.png')
w = img.shape[1]
h = img.shape[0]

scr = np.array(sct.grab(screen_grab_dimensions))
# Cut off alpha
scr_remove = scr[:,:,:3]

result = cv2.matchTemplate(scr_remove, img, cv2.TM_CCOEFF_NORMED)
_, max_val, _, max_loc = cv2.minMaxLoc(result)
print(f"Max Val: {max_val} Max Loc: {max_loc}")
src = scr.copy()

if max_val > .85:
    cv2.rectangle(scr, max_loc, (max_loc[0] + w, max_loc[1] + h), (0, 255, 255), 2)
    print(f"Position: {pg.position(max_loc[0], max_loc[1])}")
    pg.moveTo(max_loc[1], max_loc[0])
    pg.click()
    # will delete below
    cv2.imshow('Screen Shot', scr)
    cv2.waitKey()
    cv2.destroyAllWindows()
How many English words
do you know?
Test your English vocabulary size, and measure
how many words do you know
Online Test
Powered by Examplum