paip.验证码识别---分割.--使用投影直方图
paip.验证码识别---分割.--使用投影直方图
验证码识别的时候,需要纵向分割字符。需要识别字符的边界..此时可以使用投影直方图
1.做y轴的投影 2. 在直方图观察像素的分布

C#代码
Bitmap projectHistogram(Bitmapbmp)
{
// stats
if (histo!=null)
histo= null;
int width=bmp.Width;
int height=bmp.Height;
histo= new int[width];
for (inty=0; y<height; y++)
for (intx=0; x<width; x++)
{
Colorcolor=bmp.GetPixel(x, y);
if (color.R<50&&color.G<50&&color.B<50)
//if (color.A > 200)
histo[x]++;
}
// draw
//int max = getMax(histo);
Bitmaptmp= new Bitmap(width,height);
using (Graphicsg=Graphics.FromImage(tmp))
for (inti=0; i<width; i++)
g.DrawLine(
Pens.Black,
i,
height,
i,
height-histo[i]);
return tmp;
}
参考
图像识别练习(字符验证码、车牌号、身份证号)