OpenCV Python——报错AttributeError: module ‘cv2‘ has no attribute ‘bgsegm‘,解决办法
Python在使用
bgsubmog = cv2.bgsegm.createBackgroundSubtractorMOG()
去除背景,报错AttributeError: module ‘cv2‘ has no attribute ‘bgsegm‘
报错原因:使用的python环境中没有安装扩展包contrib
可以通过pip或者conda安装
pip install opencv-contrib-python
注意:contrib的版本需要和opencv版本一致
在cmd下
pip install opencv-contrib-python
我这里没有没有指定opencv-contrib-python版本号,自动匹配了
Using cached opencv_contrib_python-4.5.5.64-cp36-abi3-win_amd64.whl (42.2 MB)
Requirement already satisfied: numpy>=1.17.3 in c:\users\pvt\appdata\local\programs\python\python39\lib\site-packages (from opencv-contrib-python) (1.22.3)
Installing collected packages: opencv-contrib-python
Successfully installed opencv-contrib-python-4.5.5.64
可以通过
pip list 查看opencv及其他安装的模块的版本号