目标追踪之调用摄像头

from imutils.video import VideoStream
import argparse
import imutils
import time
import cv2
tracker_name= 'csrt'
OPENCV_OBJECT_TRACKERS = {
    "csrt": cv2.TrackerCSRT_create,
    "kcf": cv2.TrackerKCF_create,
    "boosting": cv2.TrackerCSRT_create,
    "mil": cv2.TrackerMIL_create,
    "tld": cv2.TrackerCSRT_create,
    "medianflow": cv2.TrackerCSRT_create,
    "mosse": cv2.TrackerCSRT_create
}
tracker = OPENCV_OBJECT_TRACKERS['csrt']()
initBB = None
print("打开摄像头...")
vs = VideoStream(src=0).start()
time.sleep(1.0)
while True:
    frame = vs.read()
    if frame is None:
        break
    frame=cv2.flip(frame,1)
    frame = imutils.resize(frame,width=500)
    (H, W) = frame.shape[:2]
    if initBB is not None:
        (success, box) = tracker.update(frame)
        if success:
            (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 == ord("s"):
        initBB = cv2.selectROI("Frame", frame, fromCenter=False,showCrosshair=True)
        tracker.init(frame, initBB)
    if key == ord("q"):
        break
vs.stop()
cv2.destroyAllwindows()

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值