我正在尝试参加科学博览会, 其中一部分是我需要进行对象计数, 但这有点棘手, 这是代码:
from imutils.video import FPS
import argparse
import imutils
import time
import cv2
tracker = cv2.LBPHRecognizer_create()
vs = cv2.VideoCapture(0)
initBB = None
while vs.isOpened():
ret,frame = vs.read()
cv2.line(frame,(933,462),(1170,(0,255),3)
if initBB is not None:
(success,box) = tracker.update(frame)
if success:
(x,y,w,h) = [int(v) for v in box]
cv2.rectangle(frame,(x,y),(x + w,y + h),255,0),2)
cX = int((x + x+w) / 2.0)
cY = int((y + y+h) / 2.0)
cv2.circle(frame,(cX,cY),4,(255,-1)
cv2.imshow("Frame",frame)
key = cv2.waitKey(1) & 0xFF
if key == ord("s"):
initBB = cv2.selectROI("Frame",frame,fromCenter=False,showCrosshair=True)
tracker.init(frame,initBB)
fps = FPS().start()
elif key == ord("q"):
break
else:
vs.release()
cv2.destroyAllWindows()
它基本上没有运行, 这是错误代码:
File "g:/資優班/科展/程式碼/HOG-real-time-test.py",line 8,in <module>
tracker = cv2.LBPHRecognizer_create()
AttributeError: module 'cv2.cv2' has no attribute 'LBPHRecognizer_create'
我尝试搜索修复方法, 但这对我没有帮助 我认为也许是OpenCV-python版本的问题, 但现在仍然可以肯定,也不知道如何解决, 我有点着急 请主人帮我 谢谢!