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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/33177376/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-19 12:56:49  来源:igfitidea点击:

What is the cv2.cv replacement in OpenCV3?

pythonopencv3.0

提问by Bill Cheatham

I'm using OpenCV3, and with the python bindings there is no cv2.cvmodule:

我正在使用 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

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?

这个代码在 OpenCV3 中的等价物是什么?



Related questions:

相关问题:

采纳答案by Miki

From OpenCV 2.X OpenCV 3.0 a few things changed.

从 OpenCV 2.X OpenCV 3.0 开始,一些事情发生了变化

Specifically:

具体来说:

  • cv2.cvdoesn't exists in OpenCV 3.0. Use simply cv2.
  • some defines changed, e.g. CV_BGR2HSVis now COLOR_BGR2HSV.
  • cv2.cvOpenCV 3.0 中不存在。简单地使用cv2
  • 一些定义发生了变化,例如CV_BGR2HSV现在是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)