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

Hi.

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 (http://answers.opencv.org/question/29...).

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: http://i.imgur.com/mNePsR7.png.

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.

Thanks!

edit retag close merge delete

Sort by » oldest newest most voted 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

more

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

Official site

GitHub

Wiki

Documentation

## Stats

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

Seen: 224 times

Last updated: Jun 24 '17