所有这些OpenCV Python接口之间有何不同? [英] What is different between all these OpenCV Python interfaces?
问题描述
有
-
opencv
(来自OpenCV的库), -
cv
(来自OpenCV的旧库)和 -
pyopencv
及其前身主要区别是什么,我应该使用哪一个?What are the main differences and which one should I use?
推荐答案
OpenCV正式发布了两种类型的Python接口,分别为
cv
和cv2
.Officially, OpenCV releases two types of Python interfaces,
cv
andcv2
.简历:
我开始研究
cv
.这样,所有OpenCV数据类型都将保留下来.例如,加载后,图像的格式为cvMat
,与C ++中的格式相同.I started working on
cv
. In this, all OpenCV data types are preserved as such. For example, when loaded, images are of formatcvMat
, same as in C++.对于数组操作,有几个功能,例如
cvSet2D
,cvGet2D
等.有些讨论说,它们比较慢.For array operations, there are several functions like
cvSet2D
,cvGet2D
, etc. And some discussions say, they are slower.要获得图像投资回报率,您需要特殊功能,例如
cvSetImageROI
.For imageROI, you need special functions like
cvSetImageROI
.如果找到轮廓,则会返回
cvSeq
结构,与Python列表或NumPy数组相比,这种结构不太好使用.If you find contours,
cvSeq
structures are returned which is not so good to work with compared to Python lists or NumPy arrays.(而且我认为,很快它将停止开发.以前,只有
cv
.后来,OpenCV随附了cv
和cv2
.现在,在最新版本中,只有cv2
模块,而cv
是cv2
内部的子类.您需要调用import cv2.cv as cv
来访问它.)(And I think, soon its development will be stopped. Earlier, there was only
cv
. Later, OpenCV came with bothcv
andcv2
. Now, there in the latest releases, there is only thecv2
module, andcv
is a subclass insidecv2
. You need to callimport cv2.cv as cv
to access it.)cv2:
最新的是
cv2
.在这种情况下,所有内容都以NumPy
对象(例如ndarray
和native Python
对象,例如lists
,tuples
,dictionary
等)返回.因此,由于有了NumPy支持,您可以在此处执行任何numpy操作.NumPy
是一个高度稳定且快速的数组处理库.And the latest one is
cv2
. In this, everything is returned asNumPy
objects likendarray
andnative Python
objects likelists
,tuples
,dictionary
, etc. So due to this NumPy support, you can do any numpy operation here.NumPy
is a highly stable and fast array processing library.例如,如果加载图像,则返回
ndarray
.For example, if you load an image, an
ndarray
is returned.array[i,j]
为您提供(i,j)位置的像素值.array[i,j]
gives you the pixel value at (i,j) position.此外,对于imageROI,可以像
ROI=array[c1:c2,r1:r2]
一样使用数组切片.无需单独的功能.Also, for imageROI, array slicing can be used like
ROI=array[c1:c2,r1:r2]
. No need of separate functions.要添加两个图像,无需调用任何函数,只需执行
res = img1+img2
. (但NumPy加法是uint8数组(如图像)的模运算.请参见文章To add two images, there isn't a need to call any function, just do
res = img1+img2
. (But NumPy addition is a modulo operation for uint8 arrays like images. See the article Difference between Matrix Arithmetic in OpenCV and Numpy to know more.返回的轮廓是Numpy数组的列表.您可以在 轮廓-1:入门 .
Contours returned are lists of Numpy arrays. You can find a detailed discussion about Contours in Contours - 1 : Getting Started.
简而言之,使用cv2可以简化所有操作,而且速度很快.
In short, with cv2 everything is simplified and pretty fast.
在堆栈溢出问题 OpenCV-Python接口,cv和cv2 .
A simple discussion on how NumPy speed up
cv2
is in Stack Overflow question Performance comparison of OpenCV-Python interfaces, cv and cv2.pyopencv :
由于我没有使用它,所以我对此并不了解.但这似乎已经停止了进一步的发展.
I don't know much about this since I haven't used it. But it seems to have stopped further development.
我认为坚持使用官方图书馆会更好.
I think it would be better to stick on to official libraries.
简而言之,我建议您使用cv2!
In short, I would recommend you to use cv2!
您可以在
.cv2模块的安装过程.html"rel =" noreferrer>在Windows中为Python安装OpenCV You can see installation procedure for the
cv2
module in Install OpenCV in Windows for Python.这篇关于所有这些OpenCV Python接口之间有何不同?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!