gpt4 book ai didi

python - 如何在 openCV python 2.7 中添加 "Tracker"

转载 作者:太空狗 更新时间:2023-10-29 20:35:05 25 4
gpt4 key购买 nike

我正在使用 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' 对象没有属性 'Tracker_create'

这是源代码:http://www.learnopencv.com/object-tracking-using-opencv-cpp-python/我正在寻找解决方案,但找不到任何有用的东西……我该怎么做才能将此模块添加到我的 opencv 库中?

最佳答案

只需安装 opencv-contrib-python

pip install opencv-contrib-python

它会起作用的!

关于python - 如何在 openCV python 2.7 中添加 "Tracker",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42387322/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com