java识别验证码

1.pom.xml添加依赖

        
		    net.sourceforge.tess4j
		    tess4j
		    3.4.8
		
                                    
      	
		
		    org.slf4j
		    slf4j-api
		    1.7.25
		

2.项目根目录添加tessdata

java识别验证码_第1张图片

3.编写测试类

import java.io.File;

import net.sourceforge.tess4j.*;

public class TesseractExample {
    public static void main(String[] args) {
        // ImageIO.scanForPlugins(); // for server environment
        File imageFile = new File("F:/CheckCode/CreateImageCode.jpg");
        ITesseract instance = new Tesseract(); // JNA Interface Mapping
        // ITesseract instance = new Tesseract1(); // JNA Direct Mapping
        // instance.setDatapath("<parentPath>"); // replace <parentPath> with path to parent directory of tessdata
        // instance.setLanguage("eng");
        try {
            String result = instance.doOCR(imageFile);
            System.out.println(result);
        } catch (TesseractException e) {
            System.err.println(e.getMessage());
        }
    }
}

注:普通验证码英文都能识别,复杂的无法识别,不能保证成功

你可能感兴趣的:(java识别验证码)