void get_raidu_parameter(BYTE * greyBuffer, int width, int height, float & raidu, int & pixelCount)
{
USHORT* sobel = new USHORT[width*height];
memset(sobel, 0, width*height*sizeof(USHORT));
{
USHORT* sobel = new USHORT[width*height];
memset(sobel, 0, width*height*sizeof(USHORT));
int x, y, v10, v11, v12;
for (y = 1; y < height - 1; y++)
{
for (x = 1; x < width - 1; x++)
{
*POINT2D_BUF(sobel, width, x, y) = abs(
GET2D_BUF(greyBuffer, width, x - 1, y - 1) +
2 * GET2D_BUF(greyBuffer, width, x - 1, y) +
GET2D_BUF(greyBuffer, width, x - 1, y + 1) -
GET2D_BUF(greyBuffer, width, x + 1, y - 1) -
2 * GET2D_BUF(greyBuffer, width, x + 1, y) -
GET2D_BUF(greyBuffer, width, x + 1, y + 1));
}
}
{
for (x = 1; x < width - 1; x++)
{
*POINT2D_BUF(sobel, width, x, y) = abs(
GET2D_BUF(greyBuffer, width, x - 1, y - 1) +
2 * GET2D_BUF(greyBuffer, width, x - 1, y) +
GET2D_BUF(greyBuffer, width, x - 1, y + 1) -
GET2D_BUF(greyBuffer, width, x + 1, y - 1) -
2 * GET2D_BUF(greyBuffer, width, x + 1, y) -
GET2D_BUF(greyBuffer, width, x + 1, y + 1));
}
}
std::vector<POINT> listPixels;
POINT pt;
POINT pt;
for (y = 1; y < height - 1; y++)
{
for (x = 1; x < width - 1; x++)
{
v11 = GET2D_BUF(sobel, width, x, y);
v10 = GET2D_BUF(sobel, width, x - 1, y);
v12 = GET2D_BUF(sobel, width, x + 1, y);
{
for (x = 1; x < width - 1; x++)
{
v11 = GET2D_BUF(sobel, width, x, y);
v10 = GET2D_BUF(sobel, width, x - 1, y);
v12 = GET2D_BUF(sobel, width, x + 1, y);
if ((v11 >= 50) && (v11 > v10) && (v11 > v12))
{
pt.x = x;
pt.y = y;
listPixels.push_back(pt);
}
}
}
delete[] sobel;
{
pt.x = x;
pt.y = y;
listPixels.push_back(pt);
}
}
}
delete[] sobel;
if (listPixels.size() == 0)
return;
return;
int total = 0;
int tmp, sameCount, x3;
int tmp, sameCount, x3;
const BYTE MAX_VAL = 50;
const BYTE THREE = 3;
const BYTE FIVE = 5;
bool isBlack;
const BYTE THREE = 3;
const BYTE FIVE = 5;
bool isBlack;
std::vector<POINT>::iterator it;
for (it = listPixels.begin(); it != listPixels.end(); it++)
{
x = it->x;
y = it->y;
for (it = listPixels.begin(); it != listPixels.end(); it++)
{
x = it->x;
y = it->y;
sameCount = 0;
isBlack = (GET2D_BUF(greyBuffer, width, x, y) <= GET2D_BUF(greyBuffer, width, x - 1, y));
isBlack = (GET2D_BUF(greyBuffer, width, x, y) <= GET2D_BUF(greyBuffer, width, x - 1, y));
for (int x2 = x; x2 > 0; x2--)
{
sameCount++;
if (abs(GET2D_BUF(greyBuffer, width, x2, y) - GET2D_BUF(greyBuffer, width, x2 - 1, y)) > MAX_VAL)//急变点,跳出
break;
{
sameCount++;
if (abs(GET2D_BUF(greyBuffer, width, x2, y) - GET2D_BUF(greyBuffer, width, x2 - 1, y)) > MAX_VAL)//急变点,跳出
break;
if (isBlack) //暗点
{
if (GET2D_BUF(greyBuffer, width, x2, y) > GET2D_BUF(greyBuffer, width, x2 - 1, y))//转折点,跳出
break;
}
else//亮点
{
if (GET2D_BUF(greyBuffer, width, x2, y) < GET2D_BUF(greyBuffer, width, x2 - 1, y))//转折点,跳出
break;
}
{
if (GET2D_BUF(greyBuffer, width, x2, y) > GET2D_BUF(greyBuffer, width, x2 - 1, y))//转折点,跳出
break;
}
else//亮点
{
if (GET2D_BUF(greyBuffer, width, x2, y) < GET2D_BUF(greyBuffer, width, x2 - 1, y))//转折点,跳出
break;
}
tmp = 0;
for (x3 = x2; x3 > 0; x3--)
{
if (abs(GET2D_BUF(greyBuffer, width, x2, y) - GET2D_BUF(greyBuffer, width, x3, y)) < THREE)
{
tmp++;
if (tmp > FIVE)
break;
}
else
break;
}
for (x3 = x2; x3 > 0; x3--)
{
if (abs(GET2D_BUF(greyBuffer, width, x2, y) - GET2D_BUF(greyBuffer, width, x3, y)) < THREE)
{
tmp++;
if (tmp > FIVE)
break;
}
else
break;
}
if (tmp > FIVE)//相似点超过5个,跳出
break;
}
break;
}
isBlack = (GET2D_BUF(greyBuffer, width, x, y) <= GET2D_BUF(greyBuffer, width, x + 1, y));
for (int x2 = x; x2 < width; x2++)
{
sameCount++;
if (abs(GET2D_BUF(greyBuffer, width, x2, y) - GET2D_BUF(greyBuffer, width, x2 + 1, y)) > MAX_VAL)
break;
{
sameCount++;
if (abs(GET2D_BUF(greyBuffer, width, x2, y) - GET2D_BUF(greyBuffer, width, x2 + 1, y)) > MAX_VAL)
break;
if (isBlack)
{
if (GET2D_BUF(greyBuffer, width, x2, y) > GET2D_BUF(greyBuffer, width, x2 + 1, y))
break;
}
else
{
if (GET2D_BUF(greyBuffer, width, x2, y) < GET2D_BUF(greyBuffer, width, x2 + 1, y))
break;
}
{
if (GET2D_BUF(greyBuffer, width, x2, y) > GET2D_BUF(greyBuffer, width, x2 + 1, y))
break;
}
else
{
if (GET2D_BUF(greyBuffer, width, x2, y) < GET2D_BUF(greyBuffer, width, x2 + 1, y))
break;
}
tmp = 0;
for (x3 = x2; x3 < width; x3++)
{
if (abs(GET2D_BUF(greyBuffer, width, x2, y) - GET2D_BUF(greyBuffer, width, x3, y)) < THREE)
{
tmp++;
if (tmp > FIVE)
break;
}
else
break;
}
for (x3 = x2; x3 < width; x3++)
{
if (abs(GET2D_BUF(greyBuffer, width, x2, y) - GET2D_BUF(greyBuffer, width, x3, y)) < THREE)
{
tmp++;
if (tmp > FIVE)
break;
}
else
break;
}
if (tmp > FIVE)
break;
}
sameCount--;
total += sameCount;
}
break;
}
sameCount--;
total += sameCount;
}
raidu = (float)total * 100.0 / listPixels.size();
pixelCount = listPixels.size();
printf("%.4f, total=%d, pixel_count=%d \n", raidu, total, pixelCount);
}
pixelCount = listPixels.size();
printf("%.4f, total=%d, pixel_count=%d \n", raidu, total, pixelCount);
}