Ask Your Question
2

How to find the intersection point of two lines

asked 2013-03-18 05:15:02 -0600

Heshan Sandeepa gravatar image

updated 2018-12-22 03:34:18 -0600

hi, i tried the HoughLines tutorial to detect the lines of a image. Now i want to find the intersection points between detected lines. Is there any in built function in opencv for this. If not can any one suggest a way how to get the line intersections in opencv? (with simple example if possible) plz help.

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
5

answered 2013-03-18 05:55:44 -0600

rics gravatar image

Andrey Kamaev has answered a similar question on Stackoverflow. This is his helper function:

// Finds the intersection of two lines, or returns false.
// The lines are defined by (o1, p1) and (o2, p2).
bool intersection(Point2f o1, Point2f p1, Point2f o2, Point2f p2,
                      Point2f &r)
{
    Point2f x = o2 - o1;
    Point2f d1 = p1 - o1;
    Point2f d2 = p2 - o2;

    float cross = d1.x*d2.y - d1.y*d2.x;
    if (abs(cross) < /*EPS*/1e-8)
        return false;

    double t1 = (x.x * d2.y - x.y * d2.x)/cross;
    r = o1 + d1 * t1;
    return true;
}
edit flag offensive delete link more

Comments

It would be good to use std::abs or fabs or the epsilon check will fail if not using namespace std.

Lucas Walter gravatar imageLucas Walter ( 2014-02-12 15:10:34 -0600 )edit
sturkmen gravatar imagesturkmen ( 2016-01-16 13:42:09 -0600 )edit

Question Tools

Stats

Asked: 2013-03-18 05:15:02 -0600

Seen: 32,905 times

Last updated: Mar 18 '13