我從別處轉(zhuǎn)載的。
原文地址為:http://www.cnblogs.com/ivanyb/archive/2011/11/25/2263043.html
之前我在<<C#簡單數(shù)字驗(yàn)證碼解析>>一文中介紹了用C#識別簡單不變形數(shù)字驗(yàn)證碼,但是對于識別變形的
下面介紹一個(gè)開源的OCR引擎Tesseract2。值得慶幸的是雖然是開源的但是它的識別率較高,并不比其他引擎差勁。網(wǎng)上介紹Tessnet2也是當(dāng)時(shí)時(shí)間排名第三的識別引擎,只是后來慢慢不維護(hù)了,目前是Google在維護(hù),大家都知道Google 在搞電子圖書館,每天都有不同類目的書被掃描成電子版。所以有G老大維護(hù),識別率差不到哪里去。呵呵。。別鄙視我。。。
Tessnet2 是用vc ++ 開發(fā)的,其中是生成Tessnet2.dll ,我們可以通過.net 來調(diào)用內(nèi)部具體類庫實(shí)現(xiàn)識別。
Tessnet2的使用:
1、點(diǎn)擊http://files.cnblogs.com/zhuxiangyu/tessnet2_32.rar鏈接下載Tessnet2.dll ,
Tessnet2是支持多國語的。語言包下載鏈接:http://code.google.com/p/tesseract-ocr/downloads/list
2、將Tessnet2.dll 添加到vs 引用中,和添加.net程序集一樣。
3、用Tessnet2進(jìn)行識別
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | WebRequest request = WebRequest.Create( " 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(); //聲明一個(gè)OCR類 ocr.SetVariable( "tessedit_char_whitelist" , "0123456789" ); //設(shè)置識別變量,當(dāng)前只能識別數(shù)字。 ocr.Init(Application.StartupPath + @"\\tmpe" , "eng" , true ); //應(yīng)用當(dāng)前語言包。注,Tessnet2是支持多國語的。語言包下載鏈接:http://code.google.com/p/tesseract-ocr/downloads/list List<tessnet2.Word> result = ocr.DoOCR(bitmap , Rectangle.Empty); //執(zhí)行識別操作 string code = result[0].Text; textBox1.Text = code; |
識別效果: