什么是OpenCV3中的cv2.cv替换?

时间:2015-10-16 18:34:51

标签: python opencv3.0

我正在使用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中此代码的等效内容是什么?

相关问题:

1 个答案:

答案 0 :(得分:35)

来自OpenCV 2.X OpenCV 3.0的一些事情changed

具体做法是:

    OpenCV 3.0中不存在
  • cv2.cv。仅使用cv2
  • 某些定义已更改,例如CV_BGR2HSV现在是COLOR_BGR2HSV

所以你需要改变这一行:

hsv_im = cv2.cvtColor(image, cv2.cv.CV_BGR2HSV)

为:

hsv_im = cv2.cvtColor(image, cv2.COLOR_BGR2HSV)