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 (int y=0; y<height; y++)

                for (int x=0; x<width; x++)

                {

                    Color color=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);

 

            Bitmap tmp= new Bitmap(width, height);

            using (Graphics g=Graphics.FromImage(tmp))

                for (int i=0; i<width; i++)

                    g.DrawLine(

                        Pens.Black,

                        i,

                        height,

                        i,

                        height-histo[i]);

 

            return tmp;

        }

 

 

 

参考

图像识别练习(字符验证码、车牌号、身份证号)

posted @ 2012-09-04 18:02  attilaxAti  阅读(29)  评论(0编辑  收藏  举报