OpenCV Q&A Forum - RSS feedhttp://answers.opencv.org/questions/OpenCV answersenCopyright <a href="http://www.opencv.org">OpenCV foundation</a>, 2012-2018.Sun, 25 Jun 2017 06:11:43 -0500Calculate x distance to line from edge at middle of y?http://answers.opencv.org/question/162151/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/2966/how-do-the-rho-and-theta-values-work-in-houghlines/).
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!
Sat, 24 Jun 2017 14:33:45 -0500http://answers.opencv.org/question/162151/calculate-x-distance-to-line-from-edge-at-middle-of-y/Answer by Tetragramm for <p>Hi. </p>
<p>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 (<a href="http://answers.opencv.org/question/2966/how-do-the-rho-and-theta-values-work-in-houghlines/">http://answers.opencv.org/question/29...</a>).</p>
<p>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: <a href="http://i.imgur.com/mNePsR7.png">http://i.imgur.com/mNePsR7.png</a>. </p>
<p>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? </p>
<p>There is always only one line in the image and it is always longer than the camera frame. </p>
<p>Thanks!</p>
http://answers.opencv.org/question/162151/calculate-x-distance-to-line-from-edge-at-middle-of-y/?answer=162175#post-id-162175Well, 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](http://docs.opencv.org/master/d9/db0/tutorial_hough_lines.html) to get two points on the line, and solve. Then x = (y-b)/m, where y = rows/2Sat, 24 Jun 2017 19:41:43 -0500http://answers.opencv.org/question/162151/calculate-x-distance-to-line-from-edge-at-middle-of-y/?answer=162175#post-id-162175Comment by FooBar for <p>Well, this is more geometry than computer vision, but here you go.</p>
<p>Turn your line into the form y = m*x+b. If you don't know how, use the <a href="http://docs.opencv.org/master/d9/db0/tutorial_hough_lines.html">example</a> to get two points on the line, and solve. Then x = (y-b)/m, where y = rows/2</p>
http://answers.opencv.org/question/162151/calculate-x-distance-to-line-from-edge-at-middle-of-y/?comment=162206#post-id-162206This representation is numerically unstable and not able to handle vertical lines.Sun, 25 Jun 2017 06:11:43 -0500http://answers.opencv.org/question/162151/calculate-x-distance-to-line-from-edge-at-middle-of-y/?comment=162206#post-id-162206