AttributeError:模块'cv2.cv2'没有属性'bgsegm

问题描述:

import numpy as np
import cv2
cap = cv2.VideoCapture('vtest.avi')
fgbg = cv2.bgsegm.createBackgroundSubtractorMOG()
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()

我遇到以下错误:AttributeError:模块'cv2.cv2'没有属性'bgsegm'.

I am getting the following error: AttributeError: module 'cv2.cv2' has no attribute 'bgsegm'.

我在Windows机器上使用带有OpenCV 3.6的Python 3.6. 我尝试使用pip install opencv-contrib-python命令,但在Windows机器上问题仍然相同.此命令有助于在Ubuntu系统上运行,但不能在Windows上运行.我在堆栈上搜索了类似的问题,但无法解决此问题.有人可以帮我吗?谢谢!

I am using Python 3.6 with OpenCV 3.6 on windows machine. I tried using the pip install opencv-contrib-python command but still the problem remains same on my windows machine. This command helped be on Ubuntu system, but not on windows. I searched similar problems on stack but couldn't solve this issue. Can someone help me out on this? Thanks!

您需要安装contrib依赖项才能使其正常运行,因为它不是标准构建的一部分.

You need to install the contrib dependencies to get this working as it isn't part of the standard build.

pip install opencv-contrib-python