所有这些 OpenCV Python 接口之间有什么不同? [英] What is different between all these OpenCV Python interfaces?

查看:48
本文介绍了所有这些 OpenCV Python 接口之间有什么不同?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

主要区别是什么,我应该使用哪一个?

What are the main differences and which one should I use?

推荐答案

OpenCV 官方发布了两种 Python 接口,cvcv2.

Officially, OpenCV releases two types of Python interfaces, cv and cv2.

简历:

我开始研究 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 format cvMat, same as in C++.

对于数组操作,有cvSet2DcvGet2D等几个函数,有些讨论说,它们比较慢.

For array operations, there are several functions like cvSet2D, cvGet2D, etc. And some discussions say, they are slower.

对于 imageROI,你需要像 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 有了cvcv2.现在,在最新版本中,只有cv2 模块,而cvcv2 内部的子类.您需要调用 import cv2.cv as cv 来访问它.)

(And I think, soon its development will be stopped. Earlier, there was only cv. Later, OpenCV came with both cv and cv2. Now, there in the latest releases, there is only the cv2 module, and cv is a subclass inside cv2. You need to call import cv2.cv as cv to access it.)

cv2:

而最新的是cv2.在这里,一切都作为 NumPy 对象返回,例如 ndarraynative Python 对象,例如 lists,tuplesdictionary 等.因此,由于此 NumPy 支持,您可以在此处执行任何 numpy 操作.NumPy 是一个高度稳定且快速的数组处理库.

And the latest one is cv2. In this, everything is returned as NumPy objects like ndarray and native Python objects like lists,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 数组的模运算.参见文章 OpenCV 和 Numpy 中矩阵算术的区别 了解更多.

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 数组的列表.您可以在 Contours - 1:入门.

Contours returned are lists of Numpy arrays. You can find a detailed discussion about Contours in Contours - 1 : Getting Started.

简而言之,使用 cv2 一切都变得简单而且非常快.

关于 NumPy 如何加速 cv2 的简单讨论在 Stack Overflow 问题 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!

您可以在在 Windows 中为 Python 安装 OpenCV.

You can see installation procedure for the cv2 module in Install OpenCV in Windows for Python.

这篇关于所有这些 OpenCV Python 接口之间有什么不同?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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