Which version of python opencv should I go for?
Having successfully installed opencv 2.0 with python bindings I'm starting to run into trouble and before I go any further I wondered if I should change to another option. As ezod on this post says:
"As a caveat, as of the 2.0 release, the new Python bindings are incomplete: many functions I would consider rather important missing. Meanwhile, the SWIG bindings are nothing short of agonizing to work with. The ctypes-opencv bindings (3rd party project), as of version 0.8.0, do not support OpenCV 2.0."
So, should I soldier on with 2.0 or should I go for ctypes? What am I missing out on either way?
I'm using OSX, python 2.5 and wanting to do tracking in 2d of moving object and neither a python nor machine vision expert!
I'm using a self-compiled OpenCV 2.0 and it's built-in python binding. Up to now I was missing 2 or 3 functions (eg FindFundamentalMat). If you get the source code of OpenCV you find a text file interfaces/python/api that defines the parameter and return types for each OpenCV function that is available from Python. Upon recompilation an automatic generator will parse this file and build the python extension. For all the cases I've been through I found that adding an appropriate definition to the api for the functions I needed, then recompiling opencv, worked quite well.
A late answer. If you do not have to depend on earlier versions, and want to use OpenCV with Python, choose the latest stable version. Today it is OpenCV 2.3.1.
The major benefit of OpenCV ≥ 2.3 for Python users: a new cv2
module in addition to the old (backwards compatible) cv
module. New cv2
module is much more pythonic and doesn't require manual memory allocations for intermediate data structures. Old cv
module is more like 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 handle all memory allocations automatically, returns only the final result. Just one line of the user code.
Vs. the old cv.FindContours
:
FindContours(image, storage [, mode [, method [, offset]]]) -> None
It requires the user to explicitly allocate "storage" before the call (+ 1 or 2 lines of code). It doesn't return the result, instead it saves it in the allocated storage (it works like a linked list, and the user has to write some loop to actually extract the data out of storage). Overall, more low-level, and more like C++ than Python. At least 4-5 lines of code in the common use case, instead of just one line with new cv2
module.
I'd recommend you use the official Python bindings to OpenCV 2.1 which as far as I've seen has feature parity with the C++ libraries. Most of them have either a pythonic wrapper, or a direct translation from the C++ version.
Python's OpenCV documentation isn't as complete as C++'s, but if you feel that the language advantages for prototyping are worth it, you'll be able to understand the Python usage from the C++ documentation.
Beware that much of the existing example code you'll find is from the previous versions and are incompatible (for example now everything resides under the cv
package), but it's not hard to figure out how update it.