示例#1
0
        public void SaveResult()
        {
            Program.mainForm.ShowMessage("正在保存验证码学习结果...", false);
            label2.Text = "保存中...";
            String pic1 = CreateDir(tbc_11.Text) + "\\" + CreateUID() + ".bmp";
            String pic2 = CreateDir(tbc_22.Text) + "\\" + CreateUID() + ".bmp";
            String pic3 = CreateDir(tbc_33.Text) + "\\" + CreateUID() + ".bmp";
            String pic4 = CreateDir(tbc_44.Text) + "\\" + CreateUID() + ".bmp";

            VerifyEntity ve = new VerifyEntity();

            if (!ConfigStore.codeTable.Contains(tbd_11.Text))
            {
                ve.LibId   = libId;
                ve.Code    = tbc_11.Text;
                ve.Data    = tbd_11.Text;
                ve.ImgPath = pic1;
                ConfigStore.codeTable.Add(ve.Data, ve);
            }
            ve = new VerifyEntity();
            if (!ConfigStore.codeTable.Contains(tbd_22.Text))
            {
                ve.LibId   = libId;
                ve.Code    = tbc_22.Text;
                ve.Data    = tbd_22.Text;
                ve.ImgPath = pic2;
                ConfigStore.codeTable.Add(ve.Data, ve);
            }
            ve = new VerifyEntity();
            if (!ConfigStore.codeTable.Contains(tbd_33.Text))
            {
                ve.LibId   = libId;
                ve.Code    = tbc_33.Text;
                ve.Data    = tbd_33.Text;
                ve.ImgPath = pic3;
                ConfigStore.codeTable.Add(ve.Data, ve);
            }
            ve = new VerifyEntity();
            if (!ConfigStore.codeTable.Contains(tbd_44.Text))
            {
                ve.LibId   = libId;
                ve.Code    = tbc_44.Text;
                ve.Data    = tbd_44.Text;
                ve.ImgPath = pic4;
                ConfigStore.codeTable.Add(ve.Data, ve);
            }
            System.Drawing.Imaging.ImageFormat imgformat = System.Drawing.Imaging.ImageFormat.Bmp;
            // 保存图片
            pic_11.Image.Save(dir + pic1, imgformat);
            pic_22.Image.Save(dir + pic2, imgformat);
            pic_33.Image.Save(dir + pic3, imgformat);
            pic_44.Image.Save(dir + pic4, imgformat);

            Program.mainForm.ShowMessage("完成");
            label2.Text      = "保存成功!";
            btn_save.Enabled = false;
            allcount.Text    = "当前总特征数:" + ConfigStore.codeTable.Count;
            SetZhunQuelv(ConfigStore.codeTable.Count);
            btn_next.Focus();
        }
示例#2
0
        public void Search(String key)
        {
            if (tempKey == key)
            {
                return;
            }
            tempKey = key;
            libArr.Clear();
            String    libId = GetLibId();
            ArrayList akeys = new ArrayList(ConfigStore.codeTable.Keys);

            if (String.IsNullOrEmpty(key))
            {
                VerifyEntity ve = null;
                for (int i = 0; i < akeys.Count; i++)
                {
                    ve = (VerifyEntity)ConfigStore.codeTable[akeys[i]];
                    if (libId.Equals(ve.LibId))
                    {
                        libArr.Add(ve);
                    }
                }
            }
            else
            {
                VerifyEntity ve = null;
                foreach (string skey in akeys)
                {
                    ve = (VerifyEntity)ConfigStore.codeTable[skey];
                    if (key != null && !key.Equals(""))
                    {
                        if (key.IndexOf(ve.Code) != -1)
                        {
                            if (libId.Equals(ve.LibId))
                            {
                                libArr.Add(ve);
                            }
                        }
                    }
                }
            }
            if (libArr.Count == 0)
            {
                btn_per.Enabled  = false;
                btn_next.Enabled = false;
                label3.Text      = "当前第0/0页。共0条记录";
                flowLayoutPanel1.Controls.Clear();
            }
            else
            {
                allIndex    = libArr.Count / pageCount + (libArr.Count % pageCount > 0 ? 1 : 0);
                label3.Text = "当前第" + pageIndex + "/" + allIndex + "页。共" + libArr.Count + "条记录";
                dragImg();
            }
        }
示例#3
0
        /// <summary>
        /// 根据数据点 获取相似码
        /// </summary>
        /// <returns></returns>
        public String similarity(string data)
        {
            string       result = "?";
            ArrayList    akeys  = new ArrayList(ConfigStore.codeTable.Keys);
            Hashtable    table  = new Hashtable();
            VerifyEntity ve1    = null;

            char[] datas = data.ToCharArray();
            char[] keys  = null;
            foreach (string skey in akeys)
            {
                ve1  = (VerifyEntity)ConfigStore.codeTable[skey];
                keys = skey.ToCharArray();
                int   leng  = keys.Length > datas.Length ? datas.Length : keys.Length;
                int   count = 0;
                float simi  = 0.0f;
                for (int i = 0; i < leng; i++)
                {
                    if (keys[i].Equals(datas[i]))
                    {
                        count++;
                    }
                }
                simi = (float)count / (float)leng;
                if (simi >= 0.95)
                {
                    result = ve1.Code;
                    break;
                }
                else if (simi >= 0.60)
                {
                    if (!table.Contains(simi))
                    {
                        table.Add(simi, ve1.Code);
                    }
                }
            }
            if (result.Equals("?") && table.Count > 0)
            {
                ArrayList simis = new ArrayList(table.Keys);
                simis.Sort();
                result = table[simis[simis.Count - 1]].ToString();
            }
            return(result);
        }
示例#4
0
        private void btn_save_Click(object sender, EventArgs e)
        {
            ArrayList    tempArr = getChangeUserControl();
            UserControl1 uc      = null;
            VerifyEntity ve      = null;

            for (int i = 0; i < tempArr.Count; i++)
            {
                uc      = (UserControl1)tempArr[i];
                ve      = (VerifyEntity)ConfigStore.codeTable[uc.GetAttr1()];
                ve.Code = uc.GetText();
                uc.SetChange(false);
                uc.SetChecked(false);
            }
            tempArr.Clear();
            tempArr = null;
            MessageBox.Show(Program.mainForm, "保存成功!");
        }
示例#5
0
        public static void WriteLibarayXml()
        {
            Program.mainForm.ShowMessage("正在保存特征码数据...", false);
            XmlDocument  myDoc = null;
            XmlElement   root  = null;
            XmlElement   ele   = null;
            ArrayList    akeys = new ArrayList(ConfigStore.codeTable.Keys);
            VerifyEntity ve    = null;

            foreach (Libaray lib in ConfigStore.libarays)
            {
                //初始化XML文档操作类
                myDoc = new XmlDocument();
                //加载XML文件
                myDoc.Load(xmlPath + lib.id + "\\data.xml");
                //将节点添加到文档中
                root = myDoc.DocumentElement;
                root.RemoveAll();

                //
                ele           = myDoc.CreateElement("title");
                ele.InnerText = lib.name;
                //在节点中添加元素
                root.AppendChild(ele);

                foreach (string skey in akeys)
                {
                    ve = (VerifyEntity)ConfigStore.codeTable[skey];
                    if (ve.LibId.Equals(lib.id))
                    {
                        ele = myDoc.CreateElement("data");
                        ele.SetAttribute("code", ve.Code);
                        ele.SetAttribute("imgPath", ve.ImgPath);
                        ele.InnerText = skey;
                        //在节点中添加元素
                        root.AppendChild(ele);
                    }
                }
                //保存
                myDoc.Save(xmlPath + lib.id + "\\data.xml");
            }
            Program.mainForm.ShowMessage("完成");
        }
示例#6
0
        public String similarity(Bitmap img)
        {
            string       result = "?";
            ArrayList    akeys  = new ArrayList(ConfigStore.codeTable.Keys);
            Hashtable    table  = new Hashtable();
            VerifyEntity ve1    = null;

            int[]  imgInt1 = GetHisogram(img);
            int[]  imgInt2 = null;
            Bitmap img2    = null;
            float  simi    = 0.0f;

            foreach (string skey in akeys)
            {
                ve1  = (VerifyEntity)ConfigStore.codeTable[skey];
                img2 = (Bitmap)Image.FromFile(dir + ve1.ImgPath);
                if (img2 != null)
                {
                    imgInt2 = GetHisogram(img2);
                    simi    = GetResult(imgInt1, imgInt2);
                    if (simi >= 0.95)
                    {
                        result = ve1.Code;
                        break;
                    }
                    else if (simi >= 0.60)
                    {
                        if (!table.Contains(simi))
                        {
                            table.Add(simi, ve1.Code);
                        }
                    }
                }
            }
            if (result.Equals("?") && table.Count > 0)
            {
                ArrayList simis = new ArrayList(table.Keys);
                simis.Sort();
                result = table[simis[simis.Count - 1]].ToString();
            }
            return(result);
        }
示例#7
0
        private void button3_Click(object sender, EventArgs e)
        {
            if (textBox2.Visible)
            {
                String libId = GetLibId();
                foreach (Libaray lib in ConfigStore.libarays)
                {
                    if (lib.id.Equals(libId))
                    {
                        lib.name = textBox2.Text;
                        break;
                    }
                }

                VerifyEntity ve = null;
                foreach (String key in ConfigStore.codeTable.Keys)
                {
                    ve = (VerifyEntity)ConfigStore.codeTable[key];
                    if (ve.LibId.Equals(libId))
                    {
                        ve.LibName = textBox2.Text;
                    }
                }
                LoadLibaray();
                ConfigStore.SaveConfig();
                button3.Text     = "修改特征库名称";
                cb_lib.Enabled   = true;
                textBox2.Visible = false;
                button4.Visible  = false;
            }
            else
            {
                textBox2.Text    = cb_lib.Text;
                button3.Text     = "保存修改";
                cb_lib.Enabled   = false;
                textBox2.Visible = true;
                button4.Visible  = true;
            }
        }
示例#8
0
        public void dragImg()
        {
            flowLayoutPanel1.Controls.Clear();
            UserControl1 uc = null;
            VerifyEntity ve = null;

            startIndex = (pageIndex - 1) * pageCount;
            endIndex   = pageIndex * pageCount;
            endIndex   = endIndex > libArr.Count ? libArr.Count : endIndex;
            for (int i = startIndex; i < endIndex; i++)
            {
                ve = (VerifyEntity)libArr[i];
                uc = new UserControl1();
                uc.SetText(ve.Code);
                uc.SetPic(ConfigStore.appDir + ve.ImgPath);
                uc.SetAttr1(ve.Data);
                flowLayoutPanel1.Controls.Add(uc);
            }
            label3.Text = "当前第" + pageIndex + "/" + allIndex + "页。共" + libArr.Count + "条记录";
            if (allIndex > 1 && pageIndex < allIndex)
            {
                btn_next.Enabled = true;
            }
            else
            {
                btn_next.Enabled = false;
            }

            if (pageIndex > 1)
            {
                btn_per.Enabled = true;
                button1.Enabled = true;
            }
            else
            {
                btn_per.Enabled = false;
                button1.Enabled = false;
            }
        }
示例#9
0
        private void button2_Click(object sender, EventArgs e)
        {
            DialogResult dr;

            dr = MessageBox.Show(Program.mainForm, "您确定要删除此特征库吗?\n【" + cb_lib.Text + "】", "提醒", MessageBoxButtons.YesNoCancel,
                                 MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1);
            if (dr != DialogResult.Yes)
            {
                return;
            }
            String libId = GetLibId();

            foreach (Libaray lib in ConfigStore.libarays)
            {
                if (lib.id.Equals(libId))
                {
                    lib.status = 999;
                    break;
                }
            }

            VerifyEntity ve = null;

            foreach (String key in ConfigStore.codeTable.Keys)
            {
                ve = (VerifyEntity)ConfigStore.codeTable[key];
                if (ve.LibId.Equals(libId))
                {
                    ConfigStore.codeTable.Remove(key);
                }
            }

            LoadLibaray();
            ConfigStore.SaveConfig();
            MessageBox.Show("删除成功!");
        }
示例#10
0
        public static void loadLibarayXml(String xmlFile, String libId)
        {
            Program.mainForm.ShowMessage("正在加载特征码数据...", false);
            XmlDocument xmlDoc = null;
            XmlNode root = null;
            XmlNodeList nodeList = null;
            XmlElement xe = null;
            VerifyEntity ve = null;
            if (xmlFile == null || libId == null)
            {
                foreach (Libaray lib in ConfigStore.libarays)
                {
                    xmlDoc = new XmlDocument();
                    xmlDoc.Load(xmlPath + lib.id + "\\data.xml");
                    // root节点
                    root = xmlDoc.SelectSingleNode("datas");
                    //获取到所有<datas>的子节点
                    nodeList = root.ChildNodes;
                    //遍历所有子节点
                    foreach (XmlNode xn in nodeList)
                    {
                        xe = (XmlElement)xn;
                        String title = "";
                        if (xe.Name.Equals("data"))
                        {
                            ve = new VerifyEntity();
                            if (!ConfigStore.codeTable.ContainsKey(xe.InnerText))
                            {
                                ve.Code = xe.GetAttribute("code");
                                ve.ImgPath = xe.GetAttribute("imgPath");
                                ve.Data = xe.InnerText;
                                ve.LibId = lib.id;
                                ve.LibName = title;
                                ConfigStore.codeTable.Add(ve.Data, ve);
                            }
                        }
                        else if (xe.Name.Equals("title"))
                        {
                            title = xe.InnerText;
                        }
                    }
                }
            }
            else
            {
                xmlDoc = new XmlDocument();
                xmlDoc.Load(xmlFile);
                // root节点
                root = xmlDoc.SelectSingleNode("datas");
                //获取到所有<datas>的子节点
                nodeList = root.ChildNodes;
                //遍历所有子节点
                foreach (XmlNode xn in nodeList)
                {
                    xe = (XmlElement)xn;
                    String title = "";
                    if (xe.Name.Equals("data"))
                    {
                        ve = new VerifyEntity();
                        if (!ConfigStore.codeTable.ContainsKey(xe.InnerText))
                        {
                            ve.Code = xe.GetAttribute("code");
                            ve.ImgPath = xe.GetAttribute("imgPath");
                            ve.Data = xe.InnerText;
                            ve.LibId = libId;
                            ve.LibName = title;
                            ConfigStore.codeTable.Add(ve.Data, ve);
                        }
                    }
                    else if (xe.Name.Equals("title"))
                    {
                        title = xe.InnerText;
                    }
                }
            }

            Program.mainForm.ShowMessage("完成");
        }
示例#11
0
        public static void loadLibarayXml(String xmlFile, String libId)
        {
            Program.mainForm.ShowMessage("正在加载特征码数据...", false);
            XmlDocument  xmlDoc   = null;
            XmlNode      root     = null;
            XmlNodeList  nodeList = null;
            XmlElement   xe       = null;
            VerifyEntity ve       = null;

            if (xmlFile == null || libId == null)
            {
                foreach (Libaray lib in ConfigStore.libarays)
                {
                    xmlDoc = new XmlDocument();
                    xmlDoc.Load(xmlPath + lib.id + "\\data.xml");
                    // root节点
                    root = xmlDoc.SelectSingleNode("datas");
                    //获取到所有<datas>的子节点
                    nodeList = root.ChildNodes;
                    //遍历所有子节点
                    foreach (XmlNode xn in nodeList)
                    {
                        xe = (XmlElement)xn;
                        String title = "";
                        if (xe.Name.Equals("data"))
                        {
                            ve = new VerifyEntity();
                            if (!ConfigStore.codeTable.ContainsKey(xe.InnerText))
                            {
                                ve.Code    = xe.GetAttribute("code");
                                ve.ImgPath = xe.GetAttribute("imgPath");
                                ve.Data    = xe.InnerText;
                                ve.LibId   = lib.id;
                                ve.LibName = title;
                                ConfigStore.codeTable.Add(ve.Data, ve);
                            }
                        }
                        else if (xe.Name.Equals("title"))
                        {
                            title = xe.InnerText;
                        }
                    }
                }
            }
            else
            {
                xmlDoc = new XmlDocument();
                xmlDoc.Load(xmlFile);
                // root节点
                root = xmlDoc.SelectSingleNode("datas");
                //获取到所有<datas>的子节点
                nodeList = root.ChildNodes;
                //遍历所有子节点
                foreach (XmlNode xn in nodeList)
                {
                    xe = (XmlElement)xn;
                    String title = "";
                    if (xe.Name.Equals("data"))
                    {
                        ve = new VerifyEntity();
                        if (!ConfigStore.codeTable.ContainsKey(xe.InnerText))
                        {
                            ve.Code    = xe.GetAttribute("code");
                            ve.ImgPath = xe.GetAttribute("imgPath");
                            ve.Data    = xe.InnerText;
                            ve.LibId   = libId;
                            ve.LibName = title;
                            ConfigStore.codeTable.Add(ve.Data, ve);
                        }
                    }
                    else if (xe.Name.Equals("title"))
                    {
                        title = xe.InnerText;
                    }
                }
            }

            Program.mainForm.ShowMessage("完成");
        }
示例#12
0
        public void SaveResult()
        {
            Program.mainForm.ShowMessage("正在保存验证码学习结果...", false);
            label2.Text = "保存中...";
            String pic1 = CreateDir(tbc_11.Text) + "\\" + CreateUID() + ".bmp";
            String pic2 = CreateDir(tbc_22.Text) + "\\" + CreateUID() + ".bmp";
            String pic3 = CreateDir(tbc_33.Text) + "\\" + CreateUID() + ".bmp";
            String pic4 = CreateDir(tbc_44.Text) + "\\" + CreateUID() + ".bmp";

            VerifyEntity ve = new VerifyEntity();
            if (!ConfigStore.codeTable.Contains(tbd_11.Text))
            {
                ve.LibId = libId;
                ve.Code = tbc_11.Text;
                ve.Data = tbd_11.Text;
                ve.ImgPath = pic1;
                ConfigStore.codeTable.Add(ve.Data, ve);
            }
            ve = new VerifyEntity();
            if (!ConfigStore.codeTable.Contains(tbd_22.Text))
            {
                ve.LibId = libId;
                ve.Code = tbc_22.Text;
                ve.Data = tbd_22.Text;
                ve.ImgPath = pic2;
                ConfigStore.codeTable.Add(ve.Data, ve);
            }
            ve = new VerifyEntity();
            if (!ConfigStore.codeTable.Contains(tbd_33.Text))
            {
                ve.LibId = libId;
                ve.Code = tbc_33.Text;
                ve.Data = tbd_33.Text;
                ve.ImgPath = pic3;
                ConfigStore.codeTable.Add(ve.Data, ve);
            }
            ve = new VerifyEntity();
            if (!ConfigStore.codeTable.Contains(tbd_44.Text))
            {
                ve.LibId = libId;
                ve.Code = tbc_44.Text;
                ve.Data = tbd_44.Text;
                ve.ImgPath = pic4;
                ConfigStore.codeTable.Add(ve.Data, ve);
            }
            System.Drawing.Imaging.ImageFormat imgformat = System.Drawing.Imaging.ImageFormat.Bmp;
            // 保存图片
            pic_11.Image.Save(dir + pic1, imgformat);
            pic_22.Image.Save(dir + pic2, imgformat);
            pic_33.Image.Save(dir + pic3, imgformat);
            pic_44.Image.Save(dir + pic4, imgformat);

            Program.mainForm.ShowMessage("完成");
            label2.Text = "保存成功!";
            btn_save.Enabled = false;
            allcount.Text = "当前总特征数:" + ConfigStore.codeTable.Count;
            SetZhunQuelv(ConfigStore.codeTable.Count);
            btn_next.Focus();
        }