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
文章来源地址https://www.toymoban.com/news/detail-731107.html
文章来源:https://www.toymoban.com/news/detail-731107.html
到了这里,关于ROI tracking by using OpenCV的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!