Originally Hough transform was aimed at detecting shapes described by an equation with a low number of parameters (e.g., lines, circles, ellipses etc.).
To detect arbitrary shapes, i.e. shapes having no simple analytical form, in 1981 Dana H. Ballard introduced the Generalized Hough Transform, GHT.
This technique requires the exact specification of the shape of the target object with a template contour, that is translated into a so-called R-table.

Applications of GHT showed that it is very effective and powerful. In particular it is robust to partial deformation and occlusion in shape, as well as tolerant to noise and cluttered scenes.
Its main disadvantage is that it requires a lot of memory and computation, unless being able to tune its parameters in a proper way.

(a contour found with GHT, note the precision of the method)

GHT's importance is not only a historical one, because it is really amazing at recognizing shapes.
Nevertheless I noticed the absolute lack of source code written with OpenCv and incredibly I've not been able to find even a c++ implementation of it at all !!!
I'm not sure that, browsing carefully on the web, I would finally bump into one of it, but the matter of the difficulty of finding it remains.
So I decided to write down my implementation of Generalized Hough Transfrom for OpenCv and a short tutorial, that is easier to understand than many others on the web, simply because it is based on the source code attached.

I'm not a native speaker of English, so I apologize for all the mistakes you are noticing and I hope someone will contribute to clean up them by sending to me a cleaned up version of all the texts I've published.

Source code is provided with my special license YCDWYWJPPBLTW*

The provided source code is aimed at two main things:
- to be a good base for your own possible implementation and modifications of GHT. So its functions should be enough efficient (but please don't forget that this technique is inherently slow in its full glory)
- to be very clear to understand, to make possible understanding how GHT works, how code makes it possible and how to easily modify it if you want Nevertheless code is not well organized in a class, which is only a rough container of variables and functions (that are ok).
It can be improved, as it has not error management, control on inputted parameters, etc. But I leave the burden of personalizing it to the ones who want to use it inside their own applications, to let them modify the class in a way that fits their needs.

(*) You Can Do Whatever You Want Just Please Provide a Back Link to This Webpage

contact: ght _at_