79262823

Date: 2024-12-08 16:13:08
Score: 1
Natty:
Report link

Found a solution by using the enumerate() function. Code changes as following :

def findtemplate():
    x = None
    for x,template in enumerate(all_templates):
        result = cv2.matchTemplate(work_image, template,
                                   method=cv2.TM_CCORR_NORMED)
        min_val, max_val, min_loc, max_loc = cv2.minMaxLoc(result)
        threshold = 0.945
        if max_val >= threshold:
            break
        else:
            continue
    return x

Now what the function does is it returns the index of the item that was found in the list. We can then take that index and get an output that confirms the match :

if findtemplate() == 3:
    print('green image was a match')

Which then results in a succesful print of the green image match .

green image was a match

That is all I wanted to achieve , the ability of mapping each item in the list and getting some sort of index that matches the item so that I could use that later on.

Thanks a lot !

Reasons:
  • Blacklisted phrase (0.5): Thanks
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Self-answer (0.5):
  • Low reputation (1):
Posted by: APizzy