What version of python opencv should i use?

Having successfully installed opencv 2.0 with python bindings, I begin to run into difficulties, and before moving on, I wondered if I should switch to another option. As the ezod on this post says:

β€œAs a warning, starting with version 2.0, the new Python bindings are incomplete: many functions that I consider quite important are missing. Meanwhile, SWIG bindings are nothing more than painful work. Ctypes-opencv bindings (Third Party Project), starting since version 0.8.0, do not support OpenCV 2.0. "

So, should I be a soldier with 2.0, or should I go for ctypes? What am I missing anyway?

I am using OSX, python 2.5 and wish to do tracking in 2d moving object, and neither python nor computer vision expert!

+7
python opencv
source share
3 answers

I am using self-compiled OpenCV 2.0 and python built-in binding. So far, I lacked 2 or 3 functions (e.g. FindFundamentalMat). If you get the OpenCV source code, you will find the text file interfaces / python / api that defines the parameters and return types for each OpenCV function available in Python. After recompiling, the automatic generator will parse this file and build the python extension. For all the cases I went through, I found that adding the appropriate definition to the api for the functions I needed, and then recompiling opencv, worked quite well.

+1
source share

Late answer. If you do not need to depend on earlier versions and want to use OpenCV with Python, select the latest stable version. Today it is OpenCV 2.3.1.

The main advantage of OpenCV β‰₯ 2.3 for Python users is the new cv2 module in addition to the old (backward compatible) cv module. The new cv2 module is much more pythonic and does not require manual memory allocations for intermediate data structures. The old cv module is more like a direct translation of the C ++ API.

For example, compare the new Python cv2.findContours (OpenCV β‰₯ 2.3):

 findContours(image, mode, method[, contours[, hierarchy[, offset]]]) -> contours, hierarchy 

It requires only three parameters and can automatically process all memory allocations; it returns only the final result. Just one line of user code.

Vs. old cv.FindContours :

 FindContours(image, storage [, mode [, method [, offset]]]) -> None 

This requires that the user explicitly allocate "storage" before the call (+ 1 or 2 lines of code). It does not return the result, instead it stores it in a dedicated storage (it works as a linked list, and the user must write some loop to actually retrieve the data from the storage). In general, lower level and more similar to C ++ than Python. At least 4-5 lines of code in the general case of use instead of one line with the new cv2 module.

+3
source share

I would recommend using official Python bindings to OpenCV 2.1 , which, as I have seen, have parity functions from the C ++ library. Most of them have either a python shell or a direct translation from the C ++ version.

The OpenCV Python documentation is not as comprehensive as C ++, but if you think the benefits of a prototyping language are worth it, you can understand the use of Python from the C ++ Documentation .

Beware that you find most of the code in existing code in previous versions and are incompatible (for example, now everything is in the cv package), but it’s easy to figure out how to update it.

0
source share

All Articles