tess4j 的简单使用案例 public static void main(String[] args) { System.out.println("doOCR on a PNG image"); File imageFile = new File("D:\\1503035204953.jpg"); String expResult = "The (quick) [brown] {fox} jumps!\nOver the $43,456.78
public static void main(String[] args) { System.out.println("doOCR on a PNG image"); File imageFile = new File("D:\\1503035204953.jpg"); String expResult = "The (quick) [brown] {fox} jumps!\nOver the $43,456.78#90 dog"; try { Tesseract result = new Tesseract(); result.setDatapath("G:\\cdh\\tessdata"); result.setLanguage("eng"); //对图进行黑白处理这里对图片黑白处理,增强识别率.这里先通过截图,截取图片中需要识别的部分 // textImage = ImageHelper.convertImageToGrayscale(ImageHelper.getSubImage(ImageIO.read(imageFile), 100, 100, 400, 100)); //图片放大5倍,增强识别率(很多图片本身无法识别,放大5倍时就可以轻易识,但是考滤到客户电脑配置低,针式打印机打印不连贯的问题,这里就放大5倍) BufferedImage textImage=ImageIO.read(imageFile); // textImage = ImageHelper.getScaledInstance(textImage, textImage.getWidth() * 1, textImage.getHeight()* 1); String hh= result.doOCR(textImage); // if(hh.contains("sohu")){ System.out.println(hh); // } } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } } ++++++++++++++++++++pom.xml++++++++++++++ net.sourceforge.tess4j tess4j3.4.0