Get coordinates template matching python
I used this code to do some template matching:
import cv2
import numpy
large_image = cv2.imread('image1.png')
small_image = cv2.imread('image2.png')
null, w, h = small_image.shape[::-1]
res = cv2.matchTemplate(large_image, small_image, cv2.TM_CCOEFF_NORMED)
loc = numpy.where(res >= 0.7)
for pt in zip(*loc[::-1]):
suh = cv2.rectangle(small_image, pt, (pt[0] + w, pt[1] + h), (0, 66, 255), 1)
cv2.imwrite('something.png', suh)
large_image is this one: C:\fakepath\image1.png small_image is this one: C:\fakepath\image2.png
The rectangle was created so that part worked, but I also wanted the two coordinates of the top left either checker boards. I tried to do a print(pt), but I got a few hundred sets of numbers. How can I get the location in pixels of both boxes?
you clearly did not understand the code, you were copypasting.
@berak I did not understand the code. And there is not much explanation on the code that I did copy. This is kind of a hybrid of many sources as the individual ones did not work. Wouldn't pt be a point though?
@berak I do intend on learning it, that is why I asked what do the numbers mean in the variable pt. I've watched just about every tutorial about image template matching I could find.