bgsubmog = cv2.bgsegm.createBackgroundSubtractorMOG() AttributeError: module 'cv2.cv2' has no attribute 'bgsegm'
时间: 2023-09-28 08:06:32 浏览: 267
根据引用\[1\]和引用\[2\]的代码和命令,你遇到的错误是因为你的OpenCV版本不支持`cv2.bgsegm.createBackgroundSubtractorMOG()`这个函数。在旧版本的OpenCV中,`cv2.bgsegm`模块可能不存在。解决这个问题的方法是更新你的OpenCV版本。
你可以尝试使用以下命令重新安装OpenCV并包含`opencv-contrib`模块:
```
pip uninstall opencv-python
pip uninstall opencv-contrib-python
pip install opencv-contrib-python
```
这将卸载旧版本的OpenCV并安装包含`opencv-contrib`模块的新版本。然后,你应该能够成功运行`cv2.bgsegm.createBackgroundSubtractorMOG()`函数了。
#### 引用[.reference_title]
- *1* [完美解决AttributeError: module ‘cv2.cv2‘ has no attribute ‘bgsegm](https://blog.csdn.net/weixin_41194129/article/details/118879072)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insert_down28v1,239^v3^insert_chatgpt"}} ] [.reference_item]
- *2* [进入视觉识别的报错,报错信息为AttributeError: module ‘cv2.cv2‘ has no attribute ‘bgsegm](https://blog.csdn.net/Deng872347348/article/details/127110593)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insert_down28v1,239^v3^insert_chatgpt"}} ] [.reference_item]
[ .reference_list ]
阅读全文