【发布时间】:2019-06-13 13:26:00
【问题描述】:
Python 表示 TrackerMedianFlow_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()
导致问题的我的行是:
tracker = cv2.TrackerMedianFlow_create()
直到代码运行为止。
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'
我希望它可以正常工作。
【问题讨论】:
标签: python opencv computer-vision cv2