AttributeError:模块'cv2.cv2'没有属性'bgsegm [英] AttributeError: module 'cv2.cv2' has no attribute 'bgsegm

查看:941
本文介绍了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

这篇关于AttributeError:模块'cv2.cv2'没有属性'bgsegm的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆