0
点赞
收藏
分享

微信扫一扫

ROI tracking by using OpenCV

惠特曼 2023-09-26 阅读 24

目录

source code:

import cv2

tracker = cv2.TrackerKCF_create()
video = cv2.VideoCapture(0) #cv2.CAP_DSHOW

while True:
    ret,frame = video.read()
    #if ret:
    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
举报

相关推荐

0 条评论