Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

like image 951
Guillem Avatar asked Aug 09 '19 09:08

Guillem


People also ask

Why can't I import cv2 in python?

Conclusion # The Python "ModuleNotFoundError: No module named 'cv2'" occurs when we forget to install the opencv-python module before importing it or install it in an incorrect environment. To solve the error, install the module by running the pip install opencv-python command.

What has no attribute createLBPHFaceRecognizer?

cv2' has no attribute 'createLBPHFaceRecognizer' Error You need to reinstall opencv-contrib so that first of all uninstall opencv-contrib with this command: pip uninstall opencv-python. Then just install opencv-contrib with this command: pip install opencv-contrib-python And my error solved.

Could not find a version that satisfies the requirement cv2 from versions none error no matching distribution found for cv2?

To Solve Could not find a version that satisfies the requirement cv2 (from versions: ) No matching distribution found for cv2 Error You are facing this error because of you are opencv and cv2 are not the python package names Actually Both packages included as part of the opencv-python package available to install from ...


3 Answers

As mentioned in the OpenCV pypi web page:

  1. If you have previous 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.

like image 74
Guillem Avatar answered Oct 18 '22 06:10

Guillem


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
like image 37
Aditya Bhattacharya Avatar answered Oct 18 '22 05:10

Aditya Bhattacharya


pip install opencv-contrib-python --upgrade

works for me.

like image 1
R. Marolahy Avatar answered Oct 18 '22 05:10

R. Marolahy