我正在使用OpenCV3,并且使用python绑定没有cv2.cv
模块:
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
但是,我有一些格式的遗留代码:
hsv_im = cv2.cvtColor(image, cv2.cv.CV_BGR2HSV)
运行时,我收到错误:
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'
OpenCV3中此代码的等效内容是什么?
答案 0 :(得分:35)
来自OpenCV 2.X OpenCV 3.0的一些事情changed。
具体做法是:
cv2.cv
。仅使用cv2
。CV_BGR2HSV
现在是COLOR_BGR2HSV
。所以你需要改变这一行:
hsv_im = cv2.cvtColor(image, cv2.cv.CV_BGR2HSV)
为:
hsv_im = cv2.cvtColor(image, cv2.COLOR_BGR2HSV)