天天看点

Python 使用cv2模块 进入视觉识别的报错,报错信息为AttributeError: module ‘cv2.cv2‘ has no attribute ‘bgsegm

Python 使用cv2模块 进入视觉识别的报错,报错信息为AttributeError: module ‘cv2.cv2’ has no attribute 'bgsegm

Python 使用cv2模块 进入视觉识别的报错,报错信息为AttributeError: module ‘cv2.cv2‘ has no attribute ‘bgsegm

问题描述——cv2模块 进入视觉识别的报错,报错信息为AttributeError: module ‘cv2.cv2’ has no attribute 'bgsegm

Python 使用cv2模块 进入视觉识别的报错,报错信息为AttributeError: module ‘cv2.cv2‘ has no attribute ‘bgsegm

问题原因

网上看了不少文章发现是少了这个模块导致的

后面使用命令安装模块就可以解决,

pip install opencv-contrib-python      

但是我这边早就安装了这个模块,还是报错

Python 使用cv2模块 进入视觉识别的报错,报错信息为AttributeError: module ‘cv2.cv2‘ has no attribute ‘bgsegm

后面发现opencv安装顺序可以不对,导致识别不到这个模块

解决方法

使用下面命令重新安装

pip uninstall opencv-python
pip uninstall opencv-contrib-python
pip install opencv-contrib-python      
Python 使用cv2模块 进入视觉识别的报错,报错信息为AttributeError: module ‘cv2.cv2‘ has no attribute ‘bgsegm

测试代码如图