5

When I am running the command from cv2.ximgproc import guidedFilter, I am getting an error: ModuleNotFoundError: No module named 'cv2.ximgproc'

I searched the Internet for possible reasons, and I found out that I should run a command pip install opencv--contrib-python on the terminal, which I did. Even after doing that, I am getting the same error.

Please note that I am not very good at programming and technical stuff, so please explain in simple terms. I have a mac, and I am using Anaconda for writing my codes.

Winter 2019
  • 93
  • 2
  • 5

3 Answers3

9

You need to uninstall the regular opencv package first.

First uninstall both regular opencv as well as contrib package:

pip uninstall opencv-python
pip uninstall opencv-contrib-python

Then install the contrib package:

pip install opencv-contrib-python

You can refer to this post for more information: Module 'cv2.cv2' has no attribute 'ximgproc'

Saeid Bagheri
  • 161
  • 1
  • 8
0

I have written a python script as follows:

from cv2.ximgproc import guidedFilter
print("hello")

Initially it was giving me the same error : 'ModuleNotFoundError: No module named 'cv2.ximgproc'. But then i ran the command "pip install opencv--contrib-python" and after that it prints "hello" i.e it is detecting the ximgproc module. please check the below screenshot.enter image description here

Check once the installation of opencv--contrib module. There is some problem at that stage.

Tahera Tabassum
  • 264
  • 1
  • 9
0

Make sure that the versions of OpenCV and opencv-contrib-python that you have installed are compatible with each other. If they are not, you may encounter issues when trying to import certain modules or functions. Check the versions of the packages with:

pip show opencv-python opencv-contrib-python

uninstall the existing packages and then install again with the compatible versions:

pip uninstall opencv-python opencv-contrib-python

pip install opencv-python==4.5.4.58 opencv-contrib-python==4.5.4.58
Esin
  • 1
  • 1