Module 'cv2.cv2' has no attribute 'ximgproc'

拟墨画扇 提交于 2020-08-24 05:51:13

问题


I am trying to perform a selective search to an image using OpenCV but when I run my code I get this:

>>> import cv2
>>> ss = cv2.ximgproc.segmentation.createSelectiveSearchSegmentation()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: module 'cv2.cv2' has no attribute 'ximgproc'

I've seen similar problems but people solved them installing opencv-contrib-python package. I've already installed this module but the problem persists.

Here is my requirements file:

opencv-contrib-python==4.1.0.25
opencv-python==4.1.0.25

I am using a conda environment with python 3.7


回答1:


As mentioned in the OpenCV pypi web page:

  1. If you have previous installed version of OpenCV installed remove it before installation to avoid conflicts.
  2. There are 4 different opencv packages: opencv-python, opencv-contrib-python, opencv-python-headless, opencv-contrib-python-headless.
  3. You can only install one. Multiple opencv packages are incompatible.

When asking my question, I had 2 opencv packages. Therefore I first removed the two existing packages:

$ pip uninstall opencv-contrib-python opencv-python

And then, I installed only one package:

$ pip install opencv-contrib-python

Finally, the installation worked.




回答2:


This should solve the issue, if you have pip installed. I found pip installer to be better than conda installer in general.

pip install opencv-contrib-python


来源:https://stackoverflow.com/questions/57427233/module-cv2-cv2-has-no-attribute-ximgproc

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!