测试代码:public static String crackImage(String filePath) {
File imageFile = new File(filePath);
ITesseract instance = new Tesseract();
instance.setDatapath("D:\\Users\\DetectText\\tessdata");
try {
String result = instance.doOCR(imageFile);
return result;
} catch (TesseractException e) {
System.err.println(e.getMessage());
return "Error while reading image";
}
}
public static void main(String[] args) {
// TODO Auto-generated method stub
System.out.println(ImageCracker.crackImage("D:\\Users\\DetectText\\tessdata\\captcha1.png"));
}
用博客的验证码试了试,几乎可以算完全识别不出来
看来不使用针对性训练数据不行排除样本中的干扰文字和干扰折线,只保留红色文字BufferedImage initImage;
try {
initImage = ImageIO.read(new File(filePath));
int width = ini