"import cv"和"import cv"之间的区别和"import opencv.cv"使用Python + OpenCV? [英] Difference between "import cv" and "import opencv.cv" using Python + OpenCV?

查看:408
本文介绍了"import cv"和"import cv"之间的区别和"import opencv.cv"使用Python + OpenCV?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将OpenCV与Python结合使用并转换一些C ++代码.无论如何,如果我这样做:

I'm trying to use OpenCV with Python and converting some C++ code. Anyway, if I do:

import cv
img = cv.LoadImage('image.jpg')

没关系.或者:

import opencv.cv as opcv
size = opcv.cvSize(40, 50)

但是无论如何,cv模块不具有cvSize数据结构,而opencv.cv不具有LoadImage.那么,每个模块到底有什么?我尝试查看文档,但找不到它.我应该像这样使用它还是我的设置配置不正确?

But anyway, the cv module doesn't have the cvSize data structure and the opencv.cv doesn't have the LoadImage. So, what exactly does each module have? I tried looking in the documentation but couldn't find it. Am I supposed to use it like this or is my setup misconfigured?

推荐答案

真正的答案是:)"import opencv.cv"或"from opencv import cv"都是老式的包装导入.

The real answer is :) that both "import opencv.cv" or "from opencv import cv" are the old-style wrapping imports.

从OpenCV 2.0开始,使用了新式的Python包装,您应该使用的样式如下所示:

Since OpenCV 2.0, the new-style Python wrapping is used, and the style you should use looks like this:

# import only cv, no opencv
# this also brings in sub modules such as highgui
import cv
# no "cv" prepended before all method names
src_mat = cv.LoadImageM('yourfilename.png', cv.CV_LOAD_IMAGE_GRAYSCALE)
# let's show the image in a window
cv.NamedWindow('your name', 1)
cv.ShowImage('your name', src_mat)
cv.WaitKey

根据opencv 2.2源代码似乎判断,老式包装使用SWIG,新型包装使用自制.

The old-style wrappings made use of SWIG, the new-style wrappings, judging by the opencv 2.2 source code, seem to be self-made.

这篇关于"import cv"和"import cv"之间的区别和"import opencv.cv"使用Python + OpenCV?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆