C#聯通新版驗證碼識別的實現


以前寫了篇 聯通充值卡自動充值的實現,最近發現聯通官網改版了,隨便看了下發現新版的驗證碼和以前的不同,發了點時間研究了下他的識別碼,它現在的驗證碼如下

現在將識別步驟說下

1,轉換灰度圖片

2,清除2px的邊框

3,分割驗證碼個數 (4)

4,生成字模庫

經過以上步驟,可以得到下面這個效果

下面為部分實現代碼

 public String GetCheckString(Bitmap bitmap) {
            UnCodebase ud = new UnCodebase(bitmap);
            ud.GrayByPixels();
            ud.ClearPicBorder(2);
            ud.CutMap(14, 15, 0, 0);
            bitmap = ud.bmpobj;
          //  bitmap = ud.ClearNoise(128, 1);
            String chkcode = "";
            Bitmap[] arrmap = ud.SplitImg(bitmap, 4, 1);
            foreach (Bitmap item in arrmap) {
                String str = ud.GetCodebybitmap(item, 128);
                Boolean isEques = false;
                foreach (String strss in code) {
                    String[] a = strss.Split(':');
                    if (str == a[1]) {
                        chkcode += a[0];
                        isEques = true;
                        break;
                    }
                }
                if (!isEques) {
                    String strCurrent = "";
                    double max = 0.0;
                    foreach (String strss in code) {
                        int len1, len2, min, count = 0;
                        String[] a = strss.Split(':');
                        len1 = a[1].Length;
                        len2 = str.Length;
                        min = len1;
                        if (min > len2) {
                            min = len2;
                        }
                        for (int i = 0; i < min; i++) {
                            if (str[i] == a[1][i]) {
                                count++;
                            }
                        }
                        double currrent = (count * 100.0 / min);
                        if (max < currrent) {
                            max = currrent;
                            strCurrent = a[0].Trim();
                        }
                    }
                    chkcode += strCurrent.Trim();
                }
            }
            return chkcode;
        }

通過這些處理后,識別成功率在90+%以上,

下面附上測試地址,代碼  100%C#實現,方便asp.net調用,如果是C/C++實現 asp.net 調非托管的有些麻煩,非得放到System32 或是一個絕對路徑下麻煩

測試地址

http://www.fox163.com/UniconTest.aspx 

--幸福海

博客地址:http://www.cnblogs.com/ningqhai/


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM