import numpy as np import cv2 cap = cv2.VideoCapture(0) #cap = cv2.VideoCapture("pf2.AVI") #ret, frame = cap.read() #cv2.imwrite("plumones.jpg",frame) template=cv2.imread("plumonestemplate.jpg") print template.shape w,h,c = template.shape methods = ['cv2.TM_CCOEFF', 'cv2.TM_CCOEFF_NORMED', 'cv2.TM_CCORR','cv2.TM_CCORR_NORMED', 'cv2.TM_SQDIFF', 'cv2.TM_SQDIFF_NORMED'] method = methods[5] while(1): ret, frame = cap.read() res = cv2.matchTemplate(frame,template,cv2.TM_SQDIFF) min_val, max_val, min_loc, max_loc = cv2.minMaxLoc(res) print min_loc, max_loc if method in [cv2.TM_SQDIFF, cv2.TM_SQDIFF_NORMED]: top_left = min_loc else: top_left = max_loc bottom_right = (min_loc[0] + h, min_loc[1] + w) # print top_left cv2.rectangle(frame,min_loc,bottom_right, 255, 2) cv2.imshow('frame o',frame) k = cv2.waitKey(30) & 0xff if k == 27: break cap.release() cv2.destroyAllWindows()