码迷,mamicode.com
首页 > 移动开发 > 详细

C#联通新版验证码识别的实现

时间:2014-06-09 19:52:19      阅读:225      评论:0      收藏:0      [点我收藏+]

标签:c   class   blog   code   a   http   

以前写了篇 联通充值卡自动充值的实现,最近发现联通官网改版了,随便看了下发现新版的验证码和以前的不同,发了点时间研究了下他的识别码,它现在的验证码如下

bubuko.com,布布扣

现在将识别步骤说下

1,转换灰度图片

2,清除2px的边框

3,分割验证码个数 (4)

4,生成字模库

经过以上步骤,可以得到下面这个效果

bubuko.com,布布扣

下面为部分实现代码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
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/

C#联通新版验证码识别的实现,布布扣,bubuko.com

C#联通新版验证码识别的实现

标签:c   class   blog   code   a   http   

原文地址:http://www.cnblogs.com/ImaY/p/3777168.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!