Search code examples
pythonopencvcomputer-vision

Opencv: AttributeError: module 'cv2' has no attribute 'dnn'


I am just starting with computer vision. While running code I got the following error.

[INFO] loading model... Traceback (most recent call last): File "detect_faces_video.py", line 24, in net = cv2.dnn.readNetFromCaffe(args["prototxt"], args["model"]) AttributeError: module 'cv2' has no attribute 'dnn'

I believe that the error is because my opencv version is 3.1.0 and for this tutorial to work I need at least the 3.3.0 version.

So the better question would be, How can I upgrade my opencv to 3.3.0 from 3.1.0. Do I need to delete the 3.1.0 version first?

I have installed my opencv in a virtual environment.

Thanks


Solution

  • I got it to work by making another virtual environment. Then Installing the latest version of opencv.

    $ mkvirtualenv cv

    $ sudo pip3 install opencv-contrib-python