我想把自定函数建立成一个库,在写cpp文件的时候,下面的函数怎么改成构造函数?
void Leo::hough(byte *src,int width,int height,int *pR,int *pTh,int iThreshold)
{
int *pArray;
int iRMax = (int)sqrt(width * width + height * height) + 1;
int iThMax = 361;
int iTh = 0;
int iR;
int iMax = -1;
int iThMaxIndex = -1;
int iRMaxIndex = -1;
pArray = new int[iRMax * iThMax];
memset(pArray, 0, sizeof(int) * iRMax * iThMax);
float fRate = (float)(PI/180);
for (int y = 0; y < height; y++)
{
for (int x = 0; x < width; x++)
{
if(*src == 255)
{
for(iTh = 0; iTh < iThMax; iTh += 1)
{
iR = (int)(x * cos(iTh * fRate) + y * sin(iTh * fRate));
if(iR > 0)
{
pArray[iR/1 * iThMax + iTh]++;
}
}
}
src++;
} // x
} // y
for(iR = 0; iR < iRMax; iR++)
{
for(iTh = 0; iTh < iThMax; iTh++)
{
int iCount = pArray[iR * iThMax + iTh];
if(iCount > iMax)
{
iMax = iCount;
iRMaxIndex = iR;
iThMaxIndex = iTh;
}
}
}
if(iMax >= iThreshold)
{
*pR = iRMaxIndex;
*pTh = iThMaxIndex;
}
delete []pArray;
return;
} // end of Hough
|