我正在尝试在视频片段上实现背景减法功能。但是,我收到一条错误,说“"属性错误:'模块' object没有属性' createBackgroundSubtractorMOG()。我甚至尝试过createBackgroundSubtractorMOG2(),BackgroundSubtractorMOG()。这是我的代码。需要帮助!
import numpy as np
import cv2
cap = cv2.VideoCapture('clip1.avi')
fgbg = cv2.createBackgroundSubtractorGMG(detectShadows=True)
while(1):
ret, frame = cap.read()
fgmask = fgbg.apply(frame)
cv2.imshow('frame',fgmask)
k = cv2.waitKey(30) & 0xff
if k == 27:
break
cap.release()
cv2.destroyAllWindows()