import cv2
videoPath = 'Resources/video01.mp4'
videoSave = 'Resources/videoMarked02.mp4'
cap = cv2.VideoCapture(videoPath)
fps = int(round(cap.get(cv2.CAP_PROP_FPS)))
width = int(cap.get(cv2.CAP_PROP_FRAME_WIDTH))
height = int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT))
fourcc = cv2.VideoWriter_fourcc(*'XVID')
videoWriter = cv2.VideoWriter(videoSave, fourcc, fps, (width, height))
template = cv2.imread('Resources/template03.png')
theight, twidth = template.shape[:2]
while True:
ret, target = cap.read()
if not ret:
break
result = cv2.matchTemplate(target, template, cv2.TM_SQDIFF_NORMED)
cv2.normalize(result, result, 0, 1, cv2.NORM_MINMAX, -1)
min_val, max_val, min_loc, max_loc = cv2.minMaxLoc(result)
cv2.rectangle(target, min_loc, (min_loc[0] + twidth, min_loc[1] + theight), (0, 255, 225), 2)
videoWriter.write(target)
videoWriter.release()
转载请注明原文地址:https://blackberry.8miu.com/read-12937.html