OpenCV、cv、cv2的区别?

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

cv:

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++.

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

For imageROI, you need special functions like cvSetImageROI.

If you find contours, cvSeq structures are returned which is not so good to work with compared to Python lists or NumPy arrays.

(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:

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.

For example, if you load an image, an ndarray is returned.

array[i,j] gives you the pixel value at (i,j) position.

Also, for imageROI, array slicing can be used like ROI=array[c1:c2,r1:r2]. No need of separate functions.

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.

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

In short, with cv2 everything is simplified and pretty fast.

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.

In short, I would recommend you to use cv2!

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

  • 3
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值