Python说trackerMediaFlow_create()不再是cv2的属性。在
我看过这里,但不一样:OpenCV, How to pass parameters into cv2.TrackerMedianFlow_create function? 我问过几个不和谐的服务器,但都没有成功。 我用ctrl+c直接从课本上复制了这段代码,所以它应该是精确的。在
import cv2
import numpy as np
cap = cv2.VideoCapture("../data/traffic.mp4")
_, frame = cap.read()
bbox = cv2.selectROI(frame, False, True)
cv2.destroyAllWindows()
tracker = cv2.TrackerMedianFlow_create()
status_tracker = tracker.init(frame, bbox)
fps = 0
while True:
status_cap, frame = cap.read()
if not status_cap:
break
if status_tracker:
timer = cv2.getTickCount()
status_tracker, bbox = tracker.update(frame)
if status_tracker:
x, y, w, h = [int(i) for i in bbox]
cv2.rectangle(frame, (x, y), (x + w, y + h), (0, 255, 0), 15)
fps = cv2.getTickFrequency() / (cv2.getTickCount() - timer);
cv2.putText(frame, "FPS: %.0f" % fps, (0, 80), cv2.FONT_HERSHEY_SIMPLEX, 3.5, (0, 0, 0), 8);
else:
cv2.putText(frame, "Tracking failure detected", (0, 80), cv2.FONT_HERSHEY_SIMPLEX, 3.5, (0,0,255), 8)
cv2.imshow("MedianFlow tracker", frame)
k = cv2.waitKey(1)
if k == 27:
break
cv2.destroyAllWindows()
我的问题是:
^{pr2}$直到代码运行为止。在
Traceback (most recent call last):
File "D:/Documents/E-Books/Comp Vision/opencv3computervisionwithpythoncookbook_ebook/OpenCV3ComputerVisionwithPythonCookbook_Code/Chapter04/myPart5.py", line 11, in <module>
tracker = cv2.TrackerMedianFlow_create()
AttributeError: module 'cv2.cv2' has no attribute 'TrackerMedianFlow_create'
我希望它能正常工作。在
TrackerMedianFlow
是一个module within the opencv-contrib package,并不是官方OpenCV发行版的标准。您需要安装opencv contrib包才能访问TrackerMedianFlow_create()
根据documentation,您应该在没有附加模块的情况下卸载该软件包,然后继续使用所需的其他模块重新安装opencv。在
相关问题 更多 >
编程相关推荐