There are
opencv
(the library from the OpenCV guys), cv
(the old library from the OpenCV guys) andpyopencv
with its predecessor ctypes-opencv
.What are the main differences and which one should I use?
So libopencv is a metapackage which simply references one or more related packages which are loosely grouped together. It is dedicated for installing OpenCV in Ubuntu and Debian OS. opencv-python is the OpenCV library available as a wrapper with bindings for python.
A: It's easier for users to understand opencv-python than cv2 and it makes it easier to find the package with search engines. cv2 (old interface in old OpenCV versions was named as cv ) is the name that OpenCV developers chose when they created the binding generators.
OpenCV 3 works with Python 2.7, 3.4, 3.5, 3.6 and 3.7. The unofficial OpenCV PyPi wheels work for Linux, Mac and Windows.
OpenCV is a huge open-source library for computer vision, machine learning, and image processing. OpenCV supports a wide variety of programming languages like Python, C++, Java, etc.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With