Images:
https://imgur.com/a/tzDGdyt
A border being around the strawberry
Indicates that the strawberry was detected
import pyautogui
import cv2
import numpy
import time
time.sleep(2)
pyautogui.screenshot("screenshot.png")
Image2 = cv2.imread("screenshot.png")
Image1 = cv2.imread("berry.png")
Image2 = cv2.cvtColor(Image2, cv2.COLOR_BGR2GRAY)
Image1 = cv2.cvtColor(Image1, cv2.COLOR_BGR2GRAY)
result = cv2.matchTemplate(Image2, Image1, cv2.TM_CCOEFF_NORMED)
threshold = 0.7
locations = numpy.where(result >= threshold)
for point in zip(*locations[::-1]):
cv2.rectangle(Image2, point, (point[0] + Image1.shape[1], point[1] + Image1.shape[0]), (0, 255, 0), 2)
cv2.imshow('', Image2)
cv2.waitKey(0)
Goal: To detect whether Image1 is inside Image2
No matter how scaled Image1 is