why hough transform detects two lines while there is only one line

2.5k views Asked by At

I would like to detect a line and extract its two ended points. The common approach is using the hough transform. Luckily there is a sample in OpenCV regarding is matter, therefore I've drawn a line whose two ended points p1(100,200), p2(400,200). I thought the aforementioned method will provid me with only these points. My sample image is

enter image description here

the hough transform provides me with two images which are

enter image description here

enter image description here

For Canny filter,

enter image description here

In the code, it seems that there are two lines are detected. This explains why the red line is thicker which indicates the fact that there are two lines rather than one. When I print out the number of lines, it shows me two as follows

lines.size(): 2
p1:<99,201>  p2:<401,201>
lines.size(): 2
p1:<102,198>  p2:<398,198>

Why I'm getting two lines?

1

There are 1 answers

1
MisterC On

It might be due to the width of the bins in your HoughSpace. You probably choose one of the default OpenCv functio, i.e.

HoughLines(X, X, 1, CV_PI/180, X, X, X );

The arguments that are not X define the width of the bins see. There it says:

rho : The resolution of the parameter r in pixels. We use 1 pixel.

For the first argument and for the second:

theta: The resolution of the parameter \theta in radians. We use 1 degree (CV_PI/180)

I don't now the values you chose, but you might want to choose larger ones.