struct MAXVALUE{
public int iDist;
public int iAngle;
public int iMax;
}
/*
* 检测直线
*/
void TraceBeeline(int ImageWidth,int ImageHeight,ref byte lpSrc,ref byte lpDest,int len)
{
// #define pi 3.1415927
int iMaxAngle = 90;
int iAngleNumber = 0;
//最大值
MAXVALUE MaxValue1;
unsafe { memset(&MaxValue1, 0, sizeof(MAXVALUE)); }
//循环变量
int i;
int j;
int off = 0;
int iMaxDistance = 0,iDistance = 0;
iMaxDistance = (int)sqrt(ImageWidth * ImageWidth + ImageHeight * ImageHeight);
unsafe {
int*[] lpTrans = new int*[iMaxDistance * iMaxAngle];
memset(lpTrans,0,iMaxDistance * iMaxAngle * sizeof(int));
//去掉孤立点
for(j=1,off=0;j<ImageHeight-1;j++)
for(i=1;i<ImageWidth-1;i++,off)
{
if(1==lpSrc[off])
{
if(lpSrc[off-1]==0&&lpSrc[off+1]==0&&lpSrc[off-ImageWidth]==0&&lpSrc[off+ImageWidth]==0 /
lpSrc[off-ImageWidth-1]==0&&lpSrc[off-ImageWidth+1]==0&&lpSrc[off+ImageWidth-1]==0&&lpSrc[off+ImageWidth+1]==0)
lpSrc[off]=0;
}
}
//////////////////////////////
for(j=0;j<ImageHeight;j++)
for(i=0;i<ImageWidth;i++)
{
off = j * ImageWidth + i;
if(1==lpSrc[off])
{
for(iAngleNumber=0;iAngleNumber<iMaxAngle;iAngleNumber++)
{
iDistance = (int)fabs(i * cos(iAngleNumber * 2 * PI/180.0) + j * sin(iAngleNumber * 2 * PI/180.0));
if(iDistance>=0&&iDistance<iMaxDistance)
lpTrans[iDistance * iMaxAngle + iAngleNumber]++;
}
}
}
//找到最大值
for(i = 0;i < iMaxDistance;i++)
for(iAngleNumber=0;iAngleNumber<iMaxAngle;iAngleNumber++)
{
if(lpTrans[i * iMaxAngle + iAngleNumber]>MaxValue1.iMax)
{
MaxValue1.iMax = (int)lpTrans[i * iMaxAngle + iAngleNumber];
MaxValue1.iAngle = iAngleNumber;
MaxValue1.iDist = i;
}
}
//
for(j=0;j<ImageHeight;j++)
for(i=0;i<ImageWidth;i++)
{
off = j * ImageWidth + i;
iDistance = (int)fabs(i * cos(iAngleNumber * 2 * PI/180.0) + j * sin(iAngleNumber * 2 * PI/180.0));
if(iDistance == MaxValue1.iMax)
lpDest[off]=1;
}
if(lpTrans)
{
delete lpTrans;
lpTrans = NULL;
}
请翻译成C#版的 谢谢了