当前位置:   article > 正文

opencv目标追踪CSRT_opencvcsrt

opencvcsrt
  1. import cv2
  2. cap = cv2.VideoCapture(0)
  3. ret, frame = cap.read()
  4. bbox = cv2.selectROI('frame', frame, fromCenter=False, showCrosshair=True)
  5. track = cv2.legacy.TrackerCSRT_create()
  6. track.init(frame, bbox)
  7. while True:
  8. _, frame = cap.read()
  9. ok, box = track.update(frame)
  10. if ok:
  11. (x, y, w, h) = [int(i) for i in box]
  12. cv2.rectangle(frame, pt1=(x, y), pt2=(x+w, y+h), color=(0, 255, 0), thickness=2)
  13. cv2.imshow('frame', frame)
  14. if cv2.waitKey(1) == 27:
  15. break
  16. cap.release()
  17. cv2.destroyAllWindows()

运行代码,在当前界面中截取一roi,敲下回车或者空格,持续运行,esc推出,感觉效果还是可以的。

报错:

module 'cv2' has no attribute 'legacy'

解决方法

  1. pip uninstall opencv-python
  2. pip install opencv-contrib-python --user

安装完再次运行即可

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/从前慢现在也慢/article/detail/864743
推荐阅读
相关标签
  

闽ICP备14008679号