AttributeError: module 'cv2.cv2' has no attribute 'saliency'[SOLVED]
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/
It works :
uniinstall opencv opencv_contrib and reinstall opencv_contrib only
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?
Try this:
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 havingopencv-contrib-python
was the solution for me. Thank you.I used linux on raspberry pi too.