# How to find the intersection point of two lines  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 close merge delete

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

more

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

Official site

GitHub

Wiki

Documentation

## Stats

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

Seen: 29,976 times

Last updated: Mar 18 '13