我正在使用python 2.7和opencv 3.1 我想运行一个跟踪对象的代码:
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)
但当我运行它时,我会面临这个错误:
AttributeError: 'module' object has no attribute 'Tracker_create'
这是源代码:http://www.learnopencv.com/object-tracking-using-opencv-cpp-python/ 我在寻找解决办法,但我找不到任何有用的… 如何将此模块添加到我的opencv库中?
我认为最简单和最快的方法是通过.whl文件安装。@foobar在post@kyjanond链接中给出了答案,但是您可以从以下链接获取.whl文件。
打开简历:https://pypi.python.org/pypi/opencv-python/3.3.0.10
OpenCV贡献:https://pypi.python.org/pypi/opencv-contrib-python/3.3.0.10
我在Python2.7上安装了OpenCV3.3.0,所以我下载了:
要安装,我运行了:
这是可行的,但是在OpenCV的更新版本中,tracker函数的调用方式已经改变。
GitHub存储库中的原始代码是:
我把这个改成了
这种方法似乎对我很有效。
只需安装opencv contrib python
它会起作用的!
看起来你没有用OpenCV_contrib模块编译你的OpenCV。你必须重新编译它。您可以在thisblogpost中找到一个非常好的分步指导。
编辑:
如果需要在Windows上编译,可以使用@Osama的this优秀教程
希望有帮助。
相关问题 更多 >
编程相关推荐