本文介绍了如何添加“跟踪器"在openCV python 2.7中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用python 2.7和opencv 3.1我想通过以下方式运行代码以跟踪对象:
I’m working with python 2.7 and opencv 3.1I want to run a code for tracking objects by this:
import cv2
import sys
if __name__ == '__main__' :
# Set up tracker.
# Instead of MIL, you can also use
# BOOSTING, KCF, TLD, MEDIANFLOW or GOTURN
tracker = cv2.Tracker_create("MIL")
# Read video
video = cv2.VideoCapture("videos/chaplin.mp4")
# Exit if video not opened.
if not video.isOpened():
print "Could not open video"
sys.exit()
# Read first frame.
ok, frame = video.read()
if not ok:
print 'Cannot read video file'
sys.exit()
# Define an initial bounding box
bbox = (287, 23, 86, 320)
# Uncomment the line below to select a different bounding box
# bbox = cv2.selectROI(frame, False)
# Initialize tracker with first frame and bounding box
ok = tracker.init(frame, bbox)
但是当我运行它时,我会遇到此错误:
but when I run it, I face with this error:
AttributeError: 'module' object has no attribute 'Tracker_create'
这是源代码: http://www.learnopencv .com/object-tracking-using-opencv-cpp-python/我正在寻找解决方案,但找不到任何有用的信息…我该怎么做才能将该模块添加到我的opencv库中?
Here is the source code : http://www.learnopencv.com/object-tracking-using-opencv-cpp-python/I’m searching for solutions but I can’t find anything useful…what can I do to add this module to my opencv library?
推荐答案
只需安装opencv-contrib-python
Just install opencv-contrib-python
pip install opencv-contrib-python
它将起作用!
这篇关于如何添加“跟踪器"在openCV python 2.7中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!