下面介紹一個開源的OCR引擎Tesseract2。值得慶幸的是雖然是開源的但是它的識別率較高,并不比其他引擎差勁。網上介紹Tessnet2也是當時時間排名第三的識別引擎,只是后來慢慢不維護了,目前是Google在維護,大家都知道Google 在搞電子圖書館,每天都有不同類目的書被掃描成電子版。所以有G老大維護,識別率差不到哪里去。呵呵。。別鄙視我。。。
Tessnet2 是用vc ++ 開發的,其中是生成Tessnet2.dll ,我們可以通過.net 來調用內部具體類庫實現識別。
Tessnet2的使用:
1、點擊http://files.cnblogs.com/zhuxiangyu/tessnet2_32.rar鏈接下載Tessnet2.dll ,
?? Tessnet2是支持多國語的。語言包下載鏈接:http://code.google.com/p/tesseract-ocr/downloads/list
https://github.com/tesseract-ocr/
2、將Tessnet2.dll 添加到vs 引用中,和添加.net程序集一樣。
3、用Tessnet2進行識別
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | WebRequest request = WebRequest.Create( "http://sz.2zf.cn/js/code2.asp" ); ???????????? WebResponse response = request.GetResponse(); ???????????? Stream st = response.GetResponseStream(); ???????????? Bitmap bitmap = (Bitmap)Bitmap.FromStream(st); ? UnCodebase ud = new ?UnCodebase(bitmap ); ???????????? bitmap = ud.GrayByPixels(); ???????????? ud.ClearNoise(128, 2); ???????????? pictureBox1.Image = bitmap ; tessnet2.Tesseract ocr = new ?tessnet2.Tesseract(); //聲明一個OCR類 ???????????? ocr.SetVariable( "tessedit_char_whitelist" , "0123456789" ); //設置識別變量,當前只能識別數字。 ???????????? ocr.Init(Application.StartupPath + @"\\tmpe" , "eng" , true ); //應用當前語言包。注,Tessnet2是支持多國語的。語言包下載鏈接:http://code.google.com/p/tesseract-ocr/downloads/list ???????????? List<tessnet2.Word> result = ocr.DoOCR(bitmap , Rectangle.Empty); //執行識別操作 ???????????? string ?code = result[0].Text; ???????????? textBox1.Text = code; |
?
?
識別效果:
?
代碼下載:CSharp簡單數字驗證碼解析.rar