Tess4j
前言
在日常開發當中,尤其是需要進行模擬用戶登錄的時候,各位小伙伴們多多少少會遇到一個讓人頭疼的東西,那就是驗證碼。
想要下載Tess4j的小伙伴們官網了解下,https://sourceforge.net/projects/tess4j/ 下載速度會比較慢,慢慢等待吧!
tess4j下載完成后就開始驗證碼識別之旅吧!
tess4j的目錄
實戰
引入Jar包,因為不想麻煩,直接把Tess4j中所有lib全部引入了
然后將語言庫引入至項目根目錄下
上代碼
1 import java.io.File; 2 3 import net.sourceforge.tess4j.ITesseract; 4 import net.sourceforge.tess4j.Tesseract; 5 import net.sourceforge.tess4j.TesseractException; 6 7 public class TestTess4j { 8 public static void main(String[] args) { 9 File imageFile = new File("D:/img/timg.jpg"); 10 ITesseract ins = new Tesseract(); 11 try { 12 // 若不想將tessdata放置在項目根目錄下可以指定目錄 ins.setDatapath("D:/test/tessdata"); 13 String result = ins.doOCR(imageFile); 14 System.out.println(result); 15 } catch (TesseractException e) { 16 e.printStackTrace(); 17 } finally { 18 } 19 } 20 }
一個簡單的驗證碼識別就算完成了,怎么樣是不是很簡單。
當然這種方式的話也只能用於這種簡單的驗證碼圖片了,如果復雜一點的驗證碼肯定就要先將圖片進行一下處理了。