How to use HoughLinesP to define horizontal lines in OpenCV?

I am currently trying to detect horizontal lines in an image using the HoughLinesP function in opencv using the following parameters:

HoughLinesP(linMat[i], lines, 1, CV_PI/180, 80, linMat[i].cols*(0.3), 3);

where linMat[i]is the input image. The result is this:

http://postimg.org/image/49b8wzlgz/

So far so good, I want the lines to be in the horizontal direction, as shown by the yellow line in this image (the line is drawn by hand)

http://postimg.org/image/rh9wlueo7/

I tried changing the parameter CV_PI/180to a lower value (for example, CV_PI/45), and also trying to use different values ​​for other parameters, but a horizontal line could not be generated.

What values ​​should be used in the parameters to create such a yellow line using the HoughLinesP function in opencv?

Thank!

Update

Following the advice (thanks everyone!), I tried even very extreme values, for example

HoughLinesP(linMat[i], lines, 1, CV_PI/360, 80, 1, 1);

however, the lines shown are tilted in an almost vertical direction, since this is: postimg.org/image/y5w6vm7lx/(copy- paste the link ...). I do not use an edge detection filter, for example, canny, since it could not detect thicker lines, the edges were usually discontinued.

Update 2

For clarity only, the resulting strings are generated as follows (after HoughLinesP)

for all lines

{

line( linMat[i], Point(lines[j][0], lines[j][1]), Point(lines[j][2], lines[j][3]), Scalar(0,0,255), 1, 8 );

}

+3
source share
4 answers

Hough canny , .

enter image description here

, . , lines, .

+2

double Angle = atan2(y2 - y1, x2 - x1) * 180.0 / CV_PI;

, HoughLinesP(), 0 180.

+2

, (), , HoughLinesP , - , .

, , , . 4- (x_1, y_1, x_2, y_2), .

+1
source

You can just try:

for all lines:
  if abs(lines[j][1] - lines[j][3]) == 0:
     # Horizontal line

Also, if your lines are slanted, you can try:

for all lines:
  if abs(lines[j][1] - lines[j][3]) < 20: # Tune this parameter
     # Horizontal line

I think you get the idea!

+1
source

All Articles