Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

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

As mentioned in the OpenCV pypi web page:

  • If you have previous version of OpenCV installed remove it before installation to avoid conflicts.
  • There are 4 different opencv packages: opencv-python, opencv-contrib-python, opencv-python-headless, opencv-contrib-python-headless.
  • 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.

    from the first step ".. OpenCV installed remove it before installation", emphasize on - before installation - – Ofir G Aug 20, 2020 at 13:14

    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
            

    Thanks for contributing an answer to Stack Overflow!

    • Please be sure to answer the question. Provide details and share your research!

    But avoid

    • Asking for help, clarification, or responding to other answers.
    • Making statements based on opinion; back them up with references or personal experience.

    To learn more, see our tips on writing great answers.