首先让我们看看程序的识别率,拿一种很普通的验证码来看看
大概能在60%左右。
接下来了解一下具体实现:
应用的是图像识别类库tessnet
下载dll和语言包:
密码:l5km
代码不多,简单暴力
1 try 2 { 3 string url = "http://tyt.gzsports.gov.cn/sport/image.jsp?key=0.9328223555348814"; 4 WebRequest request = WebRequest.Create(url); 5 WebResponse response = request.GetResponse(); 6 Stream st = response.GetResponseStream(); 7 8 pic_CheckCode.Image = Image.FromStream(st); 9 Bitmap bitmap = new Bitmap(pic_CheckCode.Image); 10 UnCodebase ud = new UnCodebase(bitmap); 11 ud.GrayByPixels(); 12 ud.ClearNoise(128, 2); 13 14 tessnet2.Tesseract ocr = new tessnet2.Tesseract();//声明一个OCR类 15 ocr.SetVariable("tessedit_char_whitelist", "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"); 16 ocr.Init(@"E:语言包路径", "eng", false); 17 List<tessnet2.Word> result = ocr.DoOCR(bitmap, Rectangle.Empty);//执行识别操作 18 string code = result[0].Text; 19 txt_Result.Text = code; 20 } 21 catch (Exception ex) 22 { 23 }
完。