Ask Your Question

Calculate x distance to line from edge at middle of y?

asked 2017-06-24 14:33:45 -0500


So right now I'm using HoughLines to find the distance to a line and the angle of the line. My problem is though that HoughLines calculates the distance to the line (rho) from the origin normal to the line which depends on the angle of the line as can be seen here (

I want to find the distance to the line in pixels at the middle of the frame and the angle of the line as this rough sketch shows:

Any tips on how to do this? I would guess using HoughLinesP with the different output from HoughLines and doing some calculations would work, anyone done this before?

There is always only one line in the image and it is always longer than the camera frame.


edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted

answered 2017-06-24 19:41:43 -0500

Tetragramm gravatar image

Well, this is more geometry than computer vision, but here you go.

Turn your line into the form y = m*x+b. If you don't know how, use the example to get two points on the line, and solve. Then x = (y-b)/m, where y = rows/2

edit flag offensive delete link more


This representation is numerically unstable and not able to handle vertical lines.

FooBar gravatar imageFooBar ( 2017-06-25 06:11:43 -0500 )edit
Login/Signup to Answer

Question Tools

1 follower


Asked: 2017-06-24 14:33:45 -0500

Seen: 157 times

Last updated: Jun 24 '17