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及其他安裝的模塊的版本號