line segments from same line showing different angles

asked 2015-03-31 08:13:18 -0600

bvbdort gravatar image

Hi,

I am using HoughLinesP to calculate lines from image. But the line segments from same line have different angles.

image description

the segments start and end points and angle (in degrees) and length.

id = 0 start(x,y) = (1331 , 790 )   end(x,y) = (1366 , 794 ) Angle = 6.52311 len = 35.2278
id = 2 start(x,y) = (1508 , 807 )   end(x,y) = (1543 , 810 ) Angle = 4.90158 len = 35.1283
id = 4 start(x,y) = (1291 , 786 )   end(x,y) = (1328 , 789 ) Angle = 4.63781 len = 37.1214
id = 8 start(x,y) = (1391 , 795 )   end(x,y) = (1423 , 798 ) Angle = 5.35854 len = 32.1403
id = 9 start(x,y) = (1224 , 779 )   end(x,y) = (1261 , 782 ) Angle = 4.63781 len = 37.1214

To calculate angle i used atan2(y2-y1,x2-x1)*180/3.14

I am expecting same angle since the segments are part of same line.

Is there a way to improve the angle calculation or improving line detection ?

thanks.

edit retag flag offensive close merge delete

Comments

1

i would try fitLine() here.

berak gravatar imageberak ( 2015-03-31 08:17:00 -0600 )edit
2

Or increase the maxLineGap parameter so that you get a single line instead of many segments.

FooBar gravatar imageFooBar ( 2015-03-31 08:42:01 -0600 )edit

thanks for suggestions, Since i needsegment start and endpoint for furthur calculations increasing maxLineGap is not an option. Also for fitline() i dont know in advance which segments are from sameline.

bvbdort gravatar imagebvbdort ( 2015-03-31 09:30:57 -0600 )edit

What do you mean by "same angle"? Your data (looks like a laserscanner) contains errors, so that you will never get exactly the same angles. You have a variance of around 1 degree which is not bad. So what do you expect exactly?

FooBar gravatar imageFooBar ( 2015-03-31 10:03:59 -0600 )edit

yes this is from laser data , when i use the angle of segment for calculating distance between lines its giving wrong result.

bvbdort gravatar imagebvbdort ( 2015-03-31 10:16:47 -0600 )edit

Till you use integer interpretation of lines and you havent same lenght, you cant get exactly same angle. Remember how calculate atan? if dx/dy or dy/dx isnt same you receive diferent angles ((dx +1) / (dy+1) != dx/dy if angle isnt 45 deg)

joe gravatar imagejoe ( 2015-08-20 08:32:15 -0600 )edit