【AttributeError: module ‘cv2‘ has no attribute ‘saliency‘】

AttributeError: module ‘cv2’ has no attribute ‘saliency’

problem analysis

  • If cv2 has been successfully installed and import cv2 is successful (as shown in the yellow box in the figure below), the following error will be reported when running:
    • AttributeError: module 'cv2' has no attribute 'saliency'
  • This error is usually caused by the installed version of OpenCV not including the saliency module. The saliency module is an extension module of OpenCV for saliency detection
    insert image description here

Solution

1. Make sure you install the version of OpenCV that includes the saliency module. You can check the OpenCV version and available modules by running:

 import cv2
 print(cv2.__version__)
 print(dir(cv2))

2. Make sure the saliency module is included in the output. If you installed the OpenCV version installed through pip or conda, and it does not include the saliency module, you can try the methods in 3 and 4 to reinstall OpenCV, and make sure to choose a version that includes the saliency module.

3. Use the pip command to reinstall

pip uninstall opencv-python
pip install opencv-contrib-python -i https://pypi.doubanio.com/simple/

4. Use the conda command to reinstall

conda uninstall opencv
conda install -c conda-forge opencv

5. If the above methods still cannot solve the problem, it may be because your OpenCV version does not contain the saliency module. pySaliencyMap can be installed using either of the following two commands ( 平替).

   pip install pySaliencyMap
   pip install pySaliencyMap2

Guess you like

Origin blog.csdn.net/crist_meng/article/details/131573573