//采用二值化图像,图像中黑色表示背景,白色表示目标
//定义质心计算函数
private int[] CentPoints(Bitmap src)
{
//定义存储质心坐标的数组变量
int[] CentreP = new int[2];
int M00 = 0, M01 = 0, M10 = 0;
Rectangle rect = new Rectangle(0, 0, src.Width, src.Height);
System.Drawing.Imaging.BitmapData bmpData = src.LockBits(rect, System.Drawing.Imaging.ImageLockMode.ReadWrite, System.Drawing.Imaging.PixelFormat.Format24bppRgb);
unsafe
{
int stride = bmpData.Stride;
byte* p;
byte* pIn = (byte*)bmpData.Scan0.ToPointer();
int R, G, B;
for (int y = 0; y < src.Height; y++)
{
for (int x = 0; x < src.Width; x++)
{
p = pIn;
R = p[2];
G = p[1];
B = p[0];
if (R + G + B != 0)
{
M00++;
M01 += y;
M10 += x;
}
pIn += 3;
}
pIn += stride - src.Width * 3;
}
CentreP[0] = (int)(M10 / M00);
CentreP[1] = (int)(M01 / M00);
}
src.UnlockBits(bmpData);
return CentreP;
//返回一个数组,该数组中第一个元素是质心的X坐标,
//第二个元素是质心的Y坐标
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有