int HoughTrans(PAngle pAngle, PGrayImg pSrcImg, TPrjType PrjType)
{
int i, j, p, o, Max, Tempo;
int *H;
int HWidth, HHeight;
double temp;
o = -90; p = 0;
HHeight = 4 * pSrcImg->Width + 1;
HWidth = 181;
H = (int*)malloc(HWidth*HHeight*sizeof(int));
if (NULL == H)
return 0;
for (i=-(HHeight/2); i<=(HHeight/2); i++)
for (j=-(HWidth/2); j<=(HWidth/2); j++)
*(H+(i+HHeight/2)*HWidth+j+HWidth/2) = 0;
switch (PrjType)
{
case H_FILTER:
for (i=0; i<pSrcImg->Height; i++)
for (j=0; j<pSrcImg->Width; j++)
{
if (*(pSrcImg->pImg+i*pSrcImg->Width+j) == 255)
{
for (o=-10; o<=10; o++)
{
if (o >= 0)
Tempo = o + 80;
else
Tempo = o - 80;
temp = j*cos(Tempo*PI/180.0)+i*sin(Tempo*PI/180.0);
if (temp < 0.0)
p = (int)(temp-0.5);
else
p = (int)(temp+0.5);
if ((p+HHeight/2 >= 0) && (p + HHeight/2 < HHeight))
(*(H+(p+HHeight/2)*HWidth+Tempo+HWidth/2))++;
}
}
}
Max = 0;
for (i=-HHeight/2; i<=HHeight/2; i++)
for (j=-10; j<=10; j++)
{
if (j >= 0)
Tempo = j + 80;
else
Tempo = j - 80;
if (Max<*(H+(i+HHeight/2)*HWidth+Tempo+HWidth/2))
{
Max = *(H+(i+HHeight/2)*HWidth+Tempo+HWidth/2);
o = Tempo;
p = i;
}
}
pAngle->HAngle = o;
break;
case V_FILTER:
for (i=0; i<pSrcImg->Height; i++)
for (j=0; j<pSrcImg->Width; j++)
{
if (*(pSrcImg->pImg+i*pSrcImg->Width+j) == 255)
{
for (o=-10; o<=10; o++)
{
temp = j*cos(o*PI/180.0)+i*sin(o*PI/180.0);
if (temp < 0.0)
p = (int)(temp-0.5);
else
p = (int)(temp+0.5);