I followed a tutorial on how to use cv.matchTemplate and the guy had a 98% match while i got a 51% which was in a completely different part of the picture. When he showed his result picture(comparison of his two pictures) he had a very bright spot while i didn’t (even though i took a screenshot of my screenshot).
First, Is there a way to get a higher match value?
And second, instead of selecting the brightest white pixel as a result of cv.matchTemplate, is it possible to get a match by selecting the most amount of white pixels within a certain surface area?
Keep in mind i’m not an computer engineer, i just started coding
import cv2 as cv import numpy as np haystack = cv.imread('gamepictures/haystack.png', cv.IMREAD_REDUCED_COLOR_2) grayhaystack = cv.cvtColor(haystack, cv.COLOR_BGR2GRAY) needle = cv.imread('gamepictures/needle.png', cv.IMREAD_REDUCED_COLOR_2) grayneedle =cv.cvtColor(needle, cv.COLOR_BGR2GRAY) #cv.imshow('Haystack', haystack) result = cv.matchTemplate(haystack, grayneedle, cv.TM_CCOEFF_NORMED) #1to10 min white , max white, location min_val, max_val, min_loc, max_loc = cv.minMaxLoc(result) print('Best match top left position: %s' % str(max_loc)) print("Best match confidence: %s" % max_val) needle_w = needle.shape needle_h = needle.shape top_left = max_loc bottom_right = (top_left + needle_w, top_left + needle_h) cv.rectangle(haystack, top_left, bottom_right, (0, 255,0), 2, cv.LINE_4) cv.imshow('Haystack', haystack) cv.imshow('Result', result) cv.waitKey()