source code:
import cv2
tracker = cv2.TrackerKCF_create()
video = cv2.VideoCapture(0)
while True:
ret,frame = video.read()
cv2.imshow("ROI Selector",frame)
k = cv2.waitKey(30)
if k == ord('q'):
break
bbox = cv2.selectROI(frame, False)
ok = tracker.init(frame,bbox)
cv2.destroyWindow("ROI Selector")
while True:
ret, frame = video.read()
ret, bbox = tracker.update(frame)
if ret:
p1 = (int(bbox[0]),int(bbox[1]))
p2 = (int(bbox[0]+bbox[2]),int(bbox[1]+bbox[3]))
cv2.rectangle(frame, p1,p2,(0,0,255),2,2)
cv2.imshow("Tracking", frame)
k = cv2.waitKey(1)
if k == ord('q'):
break
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30