代码实现如下:
import numpy as np
import cv2
cap = cv2.VideoCapture('output_2.avi')
fourcc = cv2.VideoWriter_fourcc(*'XVID')
out = cv2.VideoWriter('result.avi', fourcc, 20.0, (640, 480))
ret, frame = cap.read() # take first frame of the video
# setup initial location of window
r, h, c, w = 200, 170, 260, 100 # simply hardcoded the values
track_window = (c