I've been looking for answers but i just don't know know how to apply them to my use case yet. hope i can get some help :)
import cv2 as cv
import numpy as np
haystack_img = cv.imread('pokemon_tempv2.png', cv.IMREAD_UNCHANGED)
needle_img = cv.imread('pokestopv4.png', cv.IMREAD_UNCHANGED)
result = cv.matchTemplate(haystack_img, needle_img, cv.TM_SQDIFF_NORMED)
print(result)
threshold = 25
locations = np.where(result <= threshold)
print(locations)
if locations:
print('Found needle.')
needle_w = needle_img.shape[1]
needle_h = needle_img.shape[0]
line_color = (0, 255, 0)
line_type = cv.LINE_4
# Loop over all the locations and draw their rectangle
for loc in locations:
# Determine the box positions
top_left = loc
bottom_right = (top_left[0] + needle_w, top_left[1] + needle_h)
# Draw the box
cv.rectangle(haystack_img, top_left, bottom_right, line_color, line_type)
cv.imshow('Matches', haystack_img)
cv.waitKey()
#cv.imwrite('result.jpg', haystack_img)
else:
print('Needle not found.')
Error
Traceback (most recent call last):
File "C:\Users\Toastys\PycharmProjects\PokemonTraining\venv\main.py", line 31, in <module>
cv.rectangle(haystack_img, top_left, bottom_right, (line_color == 0, 255, 0), (line_type == cv.LINE_4))
cv2.error: OpenCV(4.6.0) :-1: error: (-5:Bad argument) in function 'rectangle'
> Overload resolution failed:
> - Can't parse 'pt1'. Expected sequence length 2, got 142970
> - Can't parse 'pt1'. Expected sequence length 2, got 142970
> - Can't parse 'rec'. Expected sequence length 4, got 142970
> - Can't parse 'rec'. Expected sequence length 4, got 142970


