![]() |
OpenCV
Open Source Computer Vision
|
Prev Tutorial: Canny Edge Detector
Next Tutorial: Hough Circle Transform
In this tutorial you will learn how to:
As you know, a line in the image space can be expressed with two variables. For example:
For Hough Transforms, we will express lines in the Polar system. Hence, a line equation can be written as:
Arranging the terms:
In general for each point
Meaning that each pair
If for a given
We consider only points such that
We can do the same operation above for all the points in an image. If the curves of two different points intersect in the plane
The three plots intersect in one single point
OpenCV implements two kind of Hough Line Transforms:
a. The Standard Hough Transform
b. The Probabilistic Hough Line Transform
The sample code that we will explain can be downloaded from here. A slightly fancier version (which shows both Hough standard and probabilistic with trackbars for changing the threshold values) can be found here.
Now we will apply the Hough Line Transform. We will explain how to use both OpenCV functions available for this purpose.
First, you apply the Transform:
And then you display the result by drawing the lines.
First you apply the transform:
And then you display the result by drawing the lines.
Using an input image such as a sudoku image. We get the following result by using the Standard Hough Line Transform:
And by using the Probabilistic Hough Line Transform:
You may observe that the number of lines detected vary while you change the threshold. The explanation is sort of evident: If you establish a higher threshold, fewer lines will be detected (since you will need more points to declare a line detected).