AttributeError: module 'cv2.cv2' has no attribute 'saliency'[SOLVED]

asked 2019-07-24 19:43:46 -0600

ev gravatar image

updated 2019-07-26 22:08:48 -0600

supra56 gravatar image

Using PycharmCE, python3.5, and opencv4

I cannot figure out how to get the saliency module in Pycharm... I tried updating python, reinstalling pip, reinstalling opencv-contrib-python ( which threw me an error: 'ImportError: cannot import name main '. In Pycharm, I went to settings, Project Interpretor>Add>opencv-contrib-python and I also have opencv-python installed. Why do I still get an AttributeError? PS I just tried

pip install opencv_contrib_python and the terminal responds with:

Requirement already satisfied: opencv_contrib_python in ./venv/lib/python3.7/site-packages (4.1.0.25) Requirement already satisfied: numpy>=1.14.5 in ./venv/lib/python3.7/site-packages (from opencv_contrib_python) (1.16.4)

soooo it should work right?

My use of the saliency module:

    vs = VideoStream(src=0).start()
    sleep(0.2)

    frame = vs.read()
    frame = imutils.resize(frame, width=self.win_width)
    sa = cv.saliency.MotionSaliencyBinWangApr2014_create()
    sa.setImagesize(frame.shape[1], frame.shape[0])
    sa.init()
    gray = cv.cvtColor(frame, cv.COLOR_BGR2GRAY)
    (success, saliencyMap) = sa.computeSaliency(gray)

Even the docs say this module exists in opencv-contrib-python! https://docs.opencv.org/master/

edit retag flag offensive close merge delete

Comments

2

It works :

import cv2 as cv
cv.saliency.MotionSaliencyBinWangApr2014_create()

 <saliency_MotionSaliencyBinWangApr2014 000001E1FDF7AF30>

uniinstall opencv opencv_contrib and reinstall opencv_contrib only

LBerger gravatar imageLBerger ( 2019-07-24 23:32:49 -0600 )edit
1

I uninstalled opencv-python on Pycharm and I have opencv-contrib-python installed. Now it says that cv2 is not a module. "ModuleNotFoundError: No module named 'cv2''. What is going on here?

ev gravatar imageev ( 2019-07-25 13:35:49 -0600 )edit

Try this:

pip3 install opencv-contrib-python
supra56 gravatar imagesupra56 ( 2019-07-25 19:57:25 -0600 )edit
1

I messed up the entire computer trying to get saliency but it works now haha. I just switched to another linux machine. Deleting opencv-python and only having opencv-contrib-python was the solution for me. Thank you.

ev gravatar imageev ( 2019-07-26 15:57:09 -0600 )edit

I used linux on raspberry pi too.

supra56 gravatar imagesupra56 ( 2019-07-26 22:07:11 -0600 )edit