Ask Your Question

Revision history [back]

I have problem with javacv of intersection of line using hough.

well, I need to find the intersection of two lines, I'm using javacv .. and found a code that does this in C, right here: http://opencv-code.com/tutorials/automatic-perspective-correction-for- quadrilateral-objects /

Would anyone tell me how to do it in javacv?

/ / Needed for visualization only
for (int i = 0; i <lines.size (); i + +)
{
    v = cv :: Vec4i lines [i];
    lines [i] [0] = 0;
    lines [i] [1] = ((float) v [1] - v [3]) / (v [0] - V [2]) *-v [0] + v [1];
    lines [i] [2] = src.cols;
    lines [i] [3] = ((float) v [1] - v [3]) / (v [0] - V [2]) * (src.cols - v [2]) + v [3] ;
}

cv :: Point2f computeIntersect (cv :: Vec4i the cv :: Vec4i b)
{
    int x1 = a [0], y1 = a [1], x2 = in [2], y2 = a [3];
    x3 int = b [0], y3 = b [1] x4 = b [2], y4 = b [3];

    if (float d = ((float) (x1-x2) * (y3-y4)) - ((y2-y1) * (x3-x4)))
    {
        cv :: Point2f pt;
        pt.x = ((x1 * y2 - y1 * x2) * (x3-x4) - (x2-x1) * (x3 * y4 - y3 * x4)) / d;
        pt.y = ((x1 * y2 - y1 * x2) * (y4-y3) - (y1-y2) * (x3 * y4 - y3 * x4)) / d;
        return pt;
    }
    else
        CV :: Point2f return (-1, -1);
}

...

std :: vector <cv::Point2f> corners;
for (int i = 0; i <lines.size (); i + +)
{
    for (int j = i +1 j <lines.size () j + +)
    {
        cv :: Point2f computeIntersect pt = (lines [i], lines [j]);
        if (pt.x> = 0 && pt.y> = 0)
            corners.push_back (pt);
    }
}