我不知道我是否理解错误的东西或者是否是别的东西。 这就是霍夫变换对我的影响:
你只需要检查每个像素并用这个公式计算rho和theta:
r = x.cos(θ)+ y.sin(θ)
大多数人将该公式放在从0-> 180或0-360的循环中。
为什么?
之后,您将所有值都放在累加器中。
但是由于一些黑暗和神秘的原因,所有的点来自同一条线 将给出相同的theta和r值。 这怎么可能?我真的不明白。
我尝试过,这些是我的结果: 我只是在图像上放了一条黑色的黑色水平线。该线长10px,长1px。所以我应用了公式,但没有在我的累加器中获得一个值为10的位置。我得到5个值为10的位置,为什么?
如有必要,这是我的代码:
int outputImage[400][400];
int accumulator[5000][5000]; //random size
int i,j;
int r,t;
int x1,y1,x2,y2;
/* PUT ALL VALUES IN ACCU */
for(i=0;i<imageSize[0];i++)
{
for( j=0;j<imageSize[1];j++)
{
if (inputImage[i][j] == 0x00) //just to test everything, formula only applied on the black line
{
for( t=0;t<180;t++)
{
r = i * cos(t) + j*sin(t);
accumulator[r][t] ++;
}
}
}
}
/*READ ACCU, and draw lines */
for (i=0; i<5000;i++)
{
for (j=0;j<5000;j++)
{
if(accumulator[i][j] >= 10) // If accu value >= tresholdvalue, I believe we have a line
{
x1 = accumulator[i][j] * i / (cos(accumulator[i][j] * j));
y1 = 0;
x2 = 0;
y2 = accumulator[i][j] * i / (sin(accumulator[i][j] * j));
// now i just need to draw all the lines between x1y1 and x2y2
}
}
}
谢谢!