CaptchaRecogition.ImageProcess.PreProcess C# (CSharp) 메소드

PreProcess() 공개 정적인 메소드

验证码的前期处理
public static PreProcess ( Image img, int maxNearPoints, int smallPicWidth, int smallPicHeight, int type = 2, bool is4Chars = true, int charWidth = 10 ) : List
img Image 验证码图片
maxNearPoints int 噪点最大粘连数目
smallPicWidth int 切分小图宽度
smallPicHeight int 切分小图高度
type int 灰度处理方式1:最大值2:平均值3:加权平均
is4Chars bool
charWidth int
리턴 List
        public static List<Bitmap> PreProcess(Image img, int maxNearPoints, int smallPicWidth, int smallPicHeight,int type=2,bool is4Chars=true,int charWidth=10)
        {
            img = Gray((Bitmap)img,type);
            int v = ComputeThresholdValue((Bitmap)img);
            img = RemoveBg((Bitmap)img, v);
            img = RemoveNoise((Bitmap)img, maxNearPoints);
            img = Binary((Bitmap)img);
            List<Bitmap> list = CutImage(img, smallPicWidth, smallPicHeight,is4Chars,charWidth);
            return list;
        }
        /// <summary>

Usage Example

예제 #1
0
        /// <summary>
        /// 识别
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btn_recognize_Click(object sender, EventArgs e)
        {
            if (!string.IsNullOrEmpty(zimoPath))
            {
                #region past
                //Image img = (Image)pborigin.Image.Clone();
                //img = ImageProcess.Gray((Bitmap)img);
                //int v = ImageProcess.GetDgGrayValue(img);
                //img = ImageProcess.RemoveBg((Bitmap)img, v);
                //img = ImageProcess.RemoveNoise((Bitmap)img, 1);
                //img = ImageProcess.Binary((Bitmap)img);
                //List<Bitmap> list = ImageProcess.CutImage(img, img.Width / 4, img.Height);
                //cutResult = list;
                //pictureBox2.Image = list[0];
                //pictureBox3.Image = list[1];
                //pictureBox4.Image = list[2];
                //pictureBox5.Image = list[3];
                //StringBuilder sb = new StringBuilder();
                ////读取字模
                //string[] zimo = File.ReadAllLines(zimoPath);
                //if (zimo.Length > 0)
                //{
                //    for (int j = 0; j < cutResult.Count; j++)
                //    {
                //        Dictionary<string, int> d = new Dictionary<string, int>();
                //        for (int i = 0; i < zimo.Length; i++)
                //        {
                //            string[] dic = zimo[i].Split(new string[] { "--" }, StringSplitOptions.None);
                //            //计算相似度
                //            int rate = ImageProcess.CalcRate(ImageProcess.GetBinaryCode(cutResult[j]), dic[1]);
                //            //把字符和其对应的相似度存入字典
                //            if (d.ContainsKey(dic[0]))
                //            {
                //                if (rate > d[dic[0]])
                //                {
                //                    d.Remove(dic[0]);
                //                    d.Add(dic[0], rate);
                //                }
                //            }
                //            else
                //            {
                //                d.Add(dic[0], rate);
                //            }
                //        }
                //        //找到相似度最高的
                //        sb.Append(Sort(d));
                //    }
                //}
                //else
                //{
                //    MessageBox.Show("字模数据库为空!请直接学习添加!");
                //    groupBox_Study.Visible = true;
                //}
                #endregion

                //List<Bitmap> list = ImageProcess.PreProcess(pborigin.Image, 1, pborigin.Image.Width/4,
                //    pborigin.Image.Height,graytype);
                Image         img  = (Image)pborigin.Image.Clone();
                List <Bitmap> list = ImageProcess.PreProcess(img, noiseThreshold, 20, 30, graytype, isFourChars, minWidth);
                cutResult         = list;
                pictureBox2.Image = list[0];
                if (list.Count >= 2)
                {
                    pictureBox3.Image = list[1];
                }
                else
                {
                    pictureBox3.Image = nullImg;
                }
                if (list.Count >= 3)
                {
                    pictureBox4.Image = list[2];
                }
                else
                {
                    pictureBox4.Image = nullImg;
                }
                if (list.Count >= 4)
                {
                    pictureBox5.Image = list[3];
                }
                else
                {
                    pictureBox5.Image = nullImg;
                }
                if (list.Count >= 5)
                {
                    pictureBox6.Image = list[4];
                }
                else
                {
                    pictureBox6.Image = nullImg;
                }
                if (list.Count >= 6)
                {
                    pictureBox7.Image = list[5];
                }
                else
                {
                    pictureBox7.Image = nullImg;
                }

                if (list.Count >= 7)
                {
                    pictureBox10.Image = list[6];
                }
                else
                {
                    pictureBox10.Image = nullImg;
                }
                if (list.Count >= 8)
                {
                    pictureBox11.Image = list[7];
                }
                else
                {
                    pictureBox11.Image = nullImg;
                }

                //string sb = ImageProcess.GetYZMCode(pborigin.Image, zimoPath, 1, pborigin.Image.Width/4,
                //    pborigin.Image.Height,graytype);
                Image  img2 = (Image)pborigin.Image.Clone();
                string sb   = ImageProcess.GetYZMCode(img2, zimoPath, noiseThreshold, 20, 30, graytype, isFourChars, minWidth);
                lbl_recoResult.Text = sb;
                btn_OK.Enabled      = true;
                btn_NO.Enabled      = true;
            }
            else
            {
                MessageBox.Show("没有加载字模位置!");
            }
        }