matlab和openCV中的hough变换错误?

发布于 2024-10-06 05:13:43 字数 1554 浏览 0 评论 0原文

我一直在使用 Matlab 和 OpenCV/labview 的应用程序中使用霍夫变换,发现对于某些图像,霍夫变换给出了明显错误的线拟合(一致),

这是测试图像和叠加图像。角度看起来不错,但 rho 不对。 alt text

在下图中,您将看到顶部图像尝试在原始图像的左侧填充一条线底部图像在图像右侧拟合一条线。

alt text

在Matlab中,我通过C++调用Hough函数

[H1D,theta1D,rho1D] = hough(img_1D_dilate,'ThetaResolution',0.2);

,我修剪了OpenCV HoughLines函数,所以我最终只得到我们正在填充累加器的部分。请注意,因为我的 theta 分辨率为 0.2,所以我有 900 个角度需要分析。 tabSin 和 tabCos 在函数之前定义,因此它们只是角度的正弦和余弦。

请注意,这些例程通常运行良好,但仅对于特定情况,它才会按照我所示的方式执行。

double start_angle = 60.0;
    double end_angle = 120.0;
    double num_theta = 180;
    int start_ang = num_theta * start_angle/180;
    int end_ang = num_theta * end_angle/180;
    int i,j,n,index;
        for (i = 0;i<numrows;i++)
        {
            for (j = 0;j<numcols;j++)
            {
                    if (img[i*numcols + j] == 100)
                {
                    for (n = 0;n<180;n++)
                    {   
                        index = cvRound((j*tabCos[n] + i * tabSin[n])) + (numrho-1)/2;
                        accum[(n+1) * (numrho+2) + index+1]++;
                    }
                }
            }
        }

TabCos 和 tabSin 在 Labview 中使用以下代码定义 int32 我; float64 theta_prec; float64 tabSin[180]; float64 tabCos[180];

theta_prec = 1/180*3.14159; 对于 (i = 0;i<180;i++) { tabSin[i] = sin(itheta_prec); tabCos[i] = cos(itheta_prec); 任何

建议将不胜感激

I have been using the Hough transform in my application both using Matlab and OpenCV/labview and found that for some images, the hough transform gave an obviously wrong line fit (consistently)

Here are the test and overlayed images. The angle seem right, but the rho is off.
alt text

On the image below, you will see the top image tries to fit a line to the left side of the original image and the bottom image fits a line to the right side of the image.

alt text

In Matlab, I call the Hough function through

[H1D,theta1D,rho1D] = hough(img_1D_dilate,'ThetaResolution',0.2);

in C++, i trimmed the OpenCV HoughLines function so I end up with only the part we are filling the accumulator. Note that because my theta resolution is 0.2, I have 900 angles to analyze. The tabSin and tabCos are defined prior to the function so that they are just a sin and cos of the angle.

Note that these routines generally work well, but just for specific cases it performs the way I have shown.

double start_angle = 60.0;
    double end_angle = 120.0;
    double num_theta = 180;
    int start_ang = num_theta * start_angle/180;
    int end_ang = num_theta * end_angle/180;
    int i,j,n,index;
        for (i = 0;i<numrows;i++)
        {
            for (j = 0;j<numcols;j++)
            {
                    if (img[i*numcols + j] == 100)
                {
                    for (n = 0;n<180;n++)
                    {   
                        index = cvRound((j*tabCos[n] + i * tabSin[n])) + (numrho-1)/2;
                        accum[(n+1) * (numrho+2) + index+1]++;
                    }
                }
            }
        }

TabCos and tabSin are defined in Labview with this code
int32 i;
float64 theta_prec;
float64 tabSin[180];
float64 tabCos[180];

theta_prec = 1/180*3.14159;
for (i = 0;i<180;i++)
{
tabSin[i] = sin(itheta_prec);
tabCos[i] = cos(i
theta_prec);
}

any suggestions would be greatly appreciated

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

不再见 2024-10-13 05:13:43

我想我会写下这个问题的答案。

我将 rho 和 theta 转换为 m 和 b,然后根据 m 和 b 计算 x 和 y 的值。我相信这可能在某个地方造成了一些精度误差。

通过直接从 rho 和 theta 获取 x 和 y 而不是通过 m 和 b 来修复此错误。

函数是

y = -cos(theta)/sin(theta)*x + rho/sin(theta);

I guess i'll put down the answer to this problem.

I was converting the rho and theta into m and b, then computing the values of x and y from the m and b. I believe this may have caused some precision error somewhere.

this error was fixed by obtaining x and y directly from rho and theta rather than going through m and b.

the function is

y = -cos(theta)/sin(theta)*x + rho/sin(theta);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文