Ask Your Question

Revision history [back]

Get the coordinates of a found object using a template.

So this is my code:

import cv2
import numpy as np
import pyautogui

img_bgr =  cv2.imread('gra.png')
img_gray = cv2.cvtColor(img_bgr, cv2.COLOR_BGR2GRAY)

template = cv2.imread('bones2.png', 0)

w, h = template.shape[:: -1]

res = cv2.matchTemplate(img_gray, template, cv2.TM_CCOEFF_NORMED)
threshhold = 0.90
loc = np.where( res >= threshhold)
for pt in zip(*loc[:: -1]):
    cv2.rectangle(img_bgr, pt, (pt[0] + w, pt[1] + h),(0, 255, 255), 2 )

cv2.imshow('znalezione', img_bgr)

pyautogui.moveTo( ? , ? ,duration=0.5)                                      <======== problem

my question is how can i get the coors of that object