Beispiel #1
0
 /// <summary>
 /// 字模学习入库
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void btn_CodeStudy_Click(object sender, EventArgs e)
 {
     if (cutResult != null)
     {
         string[]      zimos   = File.ReadAllLines(zimoPath);
         string        zimo    = string.Empty;
         StringBuilder sb      = new StringBuilder();
         string[]      stuCode = new string[] { txt1.Text.Trim(), txt2.Text.Trim(), txt3.Text.Trim(), txt4.Text.Trim(), txt5.Text.Trim( ), txt6.Text.Trim( ), txt7.Text.Trim(), txt8.Text.Trim() };
         for (int i = 0; i < cutResult.Count; i++)
         {
             if (!string.IsNullOrEmpty(stuCode[i]))
             {
                 ImageProcess.WriteZimo(cutResult[i], zimoPath, stuCode[i]);
             }
         }
         //File.AppendAllText(zimoPath, sb.ToString());
         txt1.Text = "";
         txt2.Text = "";
         txt3.Text = "";
         txt4.Text = "";
         txt5.Text = "";
         txt6.Text = "";
         txt7.Text = "";
         txt8.Text = "";
     }
     else
     {
         MessageBox.Show("验证码分割过程错误!");
     }
     groupBox_Study.Enabled = false;
 }
Beispiel #2
0
        /// <summary>
        /// 三种方式下灰度
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btn_gray_Click(object sender, EventArgs e)
        {
            Image img      = pborigin.Image;
            Image img_grey = (Image)img.Clone();

            imgOriginal = Image2Num((Bitmap )img_grey);
            if (!Directory.Exists("experiment\\"))
            {
                Directory.CreateDirectory("experiment\\");
            }
            //imgurl = pborigin.ImageLocation;
            WriteToFile(imgOriginal, "experiment\\" + Path.GetFileNameWithoutExtension(imgurl) + "_original.txt");
            //WriteToFile(imgGraying, "e:\\yanzhengma\\gray"+pborigin.ImageLocation);
            //灰度化处理
            //img_gray = ccccccmd.ImageHelper.Gray(img_gray, ccccccmd.ImageHelper.AlgorithmsType.AverageValue);//平均
            //img_gray = ccccccmd.ImageHelper.Gray(img_gray, ccccccmd.ImageHelper.AlgorithmsType.MaxValue );//最大值
            // img_gray = ccccccmd.ImageHelper.Gray(img_gray, ccccccmd.ImageHelper.AlgorithmsType.WeightAverage);//加权
            graytype = 2;
            if (rb_max.Checked)
            {
                graytype = 1;
            }
            if (rb_quanzhong.Checked)
            {
                graytype = 3;
            }
            img_grey  = ImageProcess.Gray((Bitmap)img_grey, graytype);
            imgGreied = Image2Num((Bitmap)img_grey);
            WriteToFile(imgGreied, "experiment\\" + Path.GetFileNameWithoutExtension(imgurl) + "_greied.txt");
            pb_grey.Image = img_grey;
        }
Beispiel #3
0
        /// <summary>
        /// 去噪点
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btn_noise_Click(object sender, EventArgs e)
        {
            Image img_noise = ImageProcess.RemoveNoise((Bitmap)pb_bg.Image.Clone(), noiseThreshold);

            //img_noise = ccccccmd.ImageHelper.ClearNoise(img_noise, v, 2);
            imgNoised = Image2Num((Bitmap)img_noise);
            WriteToFile(imgNoised, "experiment\\" + Path.GetFileNameWithoutExtension(imgurl) + "_noised.txt");
            pb_noise.Image = img_noise;
        }
Beispiel #4
0
        private void btn_cutImage_Click(object sender, EventArgs e)
        {
            //  Image img_cut =(Image) pb_gray_binary.Image.Clone();
            Image         img_cut = (Image)pb_noise_binary.Image.Clone();
            List <Bitmap> list    = ImageProcess.CutImage(img_cut, 20, 30, isFourChars, minWidth);

            cutResult = list;
            //  ccccccmd.ImageHandler handler = new ccccccmd.ImageHandler();
            //   List<Bitmap> list=     handler.CutImage(img_cut,56);
            //Bitmap[] list = ccccccmd.ImageHelper.CutImage(4,1,(Bitmap )img_cut);
            pb1.Image = list[0];
            if (list.Count >= 2)
            {
                pb2.Image = list[1];
            }
            else
            {
                pb2.Image = nullImg;
            }
            if (list.Count >= 3)
            {
                pb3.Image = list[2];
            }
            else
            {
                pb3.Image = nullImg;
            }
            if (list.Count >= 4)
            {
                pb4.Image = list[3];
            }
            else
            {
                pb4.Image = nullImg;
            }
            if (list.Count >= 5)
            {
                pb5.Image = list[4];
            }
            else
            {
                pb5.Image = nullImg;
            }
            if (list.Count >= 6)
            {
                pb6.Image = list[5];
            }
            else
            {
                pb6.Image = nullImg;
            }
        }
Beispiel #5
0
        /// <summary>
        /// 二值化处理
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btn_binary_Click(object sender, EventArgs e)
        {
            //去噪处理后的图片
            Image imgBinary = (Image)pb_noise.Image.Clone();

            //int v2 = ccccccmd.ImageHelper.ComputeThresholdValue((Bitmap)imgBinary);
            // int v2 = ImageProcess.ComputeThresholdValue((Bitmap)imgBinary);
            // imgBinary = ImageProcess.PBinary((Bitmap)imgBinary, v2);
            imgBinary   = ImageProcess.Binary((Bitmap)imgBinary);
            imgBinaried = Image2Num((Bitmap)imgBinary);
            WriteToFile(imgBinaried, "experiment\\" + Path.GetFileNameWithoutExtension(imgurl) + "_binaried.txt");
            pb_noise_binary.Image = imgBinary;
        }
Beispiel #6
0
        /// <summary>
        /// 去背景
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btn_bg_Click(object sender, EventArgs e)
        {
            Image img_noise = (Image)pb_grey.Image.Clone();
            //得到灰度图像前景色临界值

            // img_noise = ccccccmd.ImageHelper.RemoveBlock(img_noise,2);//报错
            //int v = ImageProcess.GetDgGrayValue(img_noise);
            int v = ImageProcess.ComputeThresholdValue((Bitmap)img_noise);
            //Image test = ImageProcess.RemoveBg((Bitmap)img_noise ,v );
            // int v2 = Test.ImageProcess.GetDgGrayValue(img_noise);
            Image img_bg = ImageProcess.RemoveBg((Bitmap)img_noise, v); //-----------去背景,内存法

            imgBged = Image2Num((Bitmap)img_bg);
            WriteToFile(imgBged, "experiment\\" + Path.GetFileNameWithoutExtension(imgurl) + "_bged.txt");
            pb_bg.Image = img_bg;
        }
Beispiel #7
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("没有加载字模位置!");
            }
        }