我一直在玩 opencv2 使用 Python 来跟踪多个对象 -
cv2.__version__ = 4.5.1
代码 -
import imutils
import time
import cv2
import numpy as np
trackers = cv2.legacy_MultiTracker.create()
vs = cv2.VideoCapture('4.mp4')
while True:
frame = vs.read()
if frame is None:
break
frame = frame[1]
(success, boxes) = trackers.update(frame)
for box in boxes:
(x, y, w, h) = [int(v) for v in box]
cv2.rectangle(frame, (x, y), (x + w, y + h), (0, 255, 0), 2)
cv2.imshow("Frame", frame)
key = cv2.waitKey(1) & 0xFF
if key …Run Code Online (Sandbox Code Playgroud)