I'm using OpenCV3, and with the python bindings there is no cv2.cv
module:
In [1]: import cv2 In [2]: from cv2 import cv --------------------------------------------------------------------------- ImportError Traceback (most recent call last) <ipython-input-2-15a6578c139c> in <module>() ----> 1 from cv2 import cv ImportError: cannot import name cv
However, I have some legacy code of the form:
hsv_im = cv2.cvtColor(image, cv2.cv.CV_BGR2HSV)
When running this, I get the error:
In [7]: hsv_im = cv2.cvtColor(image, cv2.cv.CV_BGR2HSV) --------------------------------------------------------------------------- AttributeError Traceback (most recent call last) <ipython-input-7-e784072551f2> in <module>() ----> 1 hsv_im = cv2.cvtColor(image, cv2.cv.CV_BGR2HSV) AttributeError: 'module' object has no attribute 'cv'
What is the equivalent of this code in OpenCV3?
import cv2 works but import cv2.cv as cv not working
Is cv2.cv missing in OpenCV 3.0?
cv2 (old interface in old OpenCV versions was named as cv ) is the name that OpenCV developers chose when they created the binding generators. This is kept as the import name to be consistent with different kind of tutorials around the internet.
The Python "ModuleNotFoundError: No module named 'cv2'" occurs when we forget to install the opencv-python module before importing it or install it in an incorrect environment. To solve the error, install the module by running the pip install opencv-python command.
Python 2.7 is the ONLY supported python version for cv 2.
OpenCV-Python is a library of Python bindings designed to solve computer vision problems. cv2. imread() method loads an image from the specified file. If the image cannot be read (because of missing file, improper permissions, unsupported or invalid format) then this method returns an empty matrix.
From OpenCV 2.X OpenCV 3.0 a few things changed.
Specifically:
cv2.cv
doesn't exists in OpenCV 3.0. Use simply cv2
.CV_BGR2HSV
is now COLOR_BGR2HSV
.So you need to change this line:
hsv_im = cv2.cvtColor(image, cv2.cv.CV_BGR2HSV)
to:
hsv_im = cv2.cvtColor(image, cv2.COLOR_BGR2HSV)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With