Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

We do not use SWIG or any other standard wrapper generation tool. We did not find such tools that would produce satisfying results.

Instead, we use our own purely Python-based solution for parsing OpenCV headers (we do not comprehend all the C++ syntax, just enough to extract declarations of the functions, classes, methods, as well as enumerations constants).

Since C/C++ API does not conveniently map to Python API (e.g. in Python we can have multiple return values, in C just one), we put in C++ headers some helper macros to give parser some high-level information about certain classes or method parameters. For example, CV_EXPORTS_W_MAP in the class declaration is equivalent to CV_EXPORTS for C++ compiler, but it instructs the header parser that the class should be converted to a Python map (dict) (which is very convenient for structures representing algorithm parameters).

The parser is at opencv/modules/python/src2/ BTW, our java wrapper generator uses the same technology and the same script to extract the API.

After all the API is extracted, we use some more python code (opencv/modules/python/src2/ to produce Python wrappers. We created this script incrementally and used the concept of clear crisp wrapper code. In other words, instead of creating "for compiler eyes only" mess, we generate wrappers as if they were manually written. They are very easy to read, and therefore, it was not difficult to debug the wrapper generator.

For 2.5.x we plan to do some refactoring of the code, but we will continue to use this technology and are very happy with it. Besides the nice warm feeling that we have the full control over the result, the generator is also super-fast and does not impose any extra dependencies.

If you want to participate, it's enough to know C/C++, Python and a bit of the Python C API.

Another strict requirement is that you should not suggest us to switch to another wrapper generator, Boost-Python or whatever :)