I am trying to calculate the line intersection point for an optical flow algorithm using the Hough transform. However, I do not get points, which should be when I use my algorithm to calculate intersections.
I save the lines as an instance of the class that I created, called ImageLine . Here is the code for my intersection method.
Point ImageLine::intersectionWith(ImageLine other) { float A2 = other.Y2() - other.Y1(); float B2 = other.X2() - other.X1(); float C2 = A2*other.X1() + B2*other.Y1(); float A1 = y2 - y1; float B1 = x2 - x1; float C1 = A1 * x1 + B1 * y1; float det = A1*B2 - A2*B1; if (det == 0) { return Point(-1,-1); } Point d = Point((B2 * C1 - B1 * C2) / det, -(A1 * C2 - A2 * C1) / det); return d; }
Is this method correct, or have I done something wrong? As far as I can tell, it should work, as well as for one point that I hard-coded, however, I could not get a good intersection when using real data.
source share