从粗线中选择线 [英] Choosing Lines From Hough Lines

查看:83
本文介绍了从粗线中选择线的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用霍夫线对此图像进行角点检测.我打算找到直线的交点作为拐角. 这是图像.

I'm using Hough Lines to do corner detection for this image. i plan to find the intersection of the lines as the corner. This is the image.

不幸的是,霍夫为我期望的每一行返回很多行

Unfortunately, Hough return lots of lines for each line I expect

我该如何调整霍夫线,以便只有四条线分别与图像上的实际线相对应?

How do I tune the Hough Lines so there is only four lines each corresponds to actual line on the image?

推荐答案

收集所有线的交点

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

您可以用谷歌算法查找两条线的交点. 一旦收集了所有相交点,就可以轻松确定最小最大值,这将为您提供左上和右下的点.从这两点可以轻松获得矩形.

You can google the algorithm to find the intersection of two lines. Once you collect all the intersection points you can easily determine the min max which will give you top-left and bottom right points. From these two points you can easily get the rectangle.

对2d点数组进行排序以找出四个角 http://opencv-code.com/tutorials/automatic -perspective-correction-for-quadrilateral-objects/请参阅这两个链接.

Here Sorting 2d point array to find out four corners & http://opencv-code.com/tutorials/automatic-perspective-correction-for-quadrilateral-objects/ Refer these two links.

这篇关于从粗线中选择线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆