gpt4 book ai didi

Python说 "TrackerMedianFlow_create()"不再是cv2的属性,库更新了吗?

转载 作者:行者123 更新时间:2023-12-02 17:29:48 25 4
gpt4 key购买 nike

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'

我希望它可以正常工作而不会出错。

最佳答案

对于 opencv 4.5.1 用户
opencv-contrib-python

import cv2
cv2.legacy_TrackerMedianFlow()

关于Python说 "TrackerMedianFlow_create()"不再是cv2的属性,库更新了吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56581577/

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