C#聯(lián)通新版驗證碼識別的實現(xiàn)
以前寫了篇 聯(lián)通充值卡自動充值的實現(xiàn),最近發(fā)現(xiàn)聯(lián)通官網(wǎng)改版了,隨便看了下發(fā)現(xiàn)新版的驗證碼和以前的不同,發(fā)了點時間研究了下他的識別碼,它現(xiàn)在的驗證碼如下:
現(xiàn)在將識別步驟說下
1,轉(zhuǎn)換灰度圖片
2,清除2px的邊框
3,分割驗證碼個數(shù) (4)
4,生成字模庫
經(jīng)過以上步驟,可以得到下面這個效果
下面為部分實現(xiàn)代碼
- 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#實現(xiàn),方便asp.net調(diào)用,如果是C/C++實現(xiàn) asp.net 調(diào)非托管的有些麻煩,非得放到System32 或是一個絕對路徑下麻煩
測試地址
http://www.fox163.com/UniconTest.aspx
本文轉(zhuǎn)自:http://www.cnblogs.com/ningqhai/p/3684318.html