import numpy as np
import cv2

temp = cv2.imread('match_bw50.jpg',0)
w, h = temp.shape[::-1]
thresh = 0.6

cap = cv2.VideoCapture('vid2.mp4')

while True:

    ret, frame = cap.read()

    if ret == True:

        gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
        #median = cv2.medianBlur(gray, 3)

        res = cv2.matchTemplate(gray, temp, cv2.TM_CCOEFF_NORMED)
        loc = np.where( res >= thresh)

        for pt in zip(*loc[::-1]):
            cv2.rectangle(gray, pt, (pt[0] + w, pt[1] + h), (255,0,0), 1)
    
        cv2.imshow('frame', gray)

        if cv2.waitKey(50) & 0xFF == ord('q'):
            break

    else:
        break

cap.release()
cv2.destroyAllWindows()

kam1.jpg

xam1.jpg