![]() |
OpenCV
Open Source Computer Vision
|
Prev Tutorial: Canny Edge Detector
Next Tutorial: Hough Circle Transform
Original author | Ana Huamán |
Compatibility | OpenCV >= 3.0 |
In this tutorial you will learn how to:
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
We consider only points such that
The three plots intersect in one single point
OpenCV implements three kind of Hough Line Transforms:
a. The Standard Hough Transform
b. The Probabilistic Hough Line Transform
c. The Weighted Hough 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).