OCRUtil { @Contract(pure = true) public String ocrCalcCaptcha(@NotNull BufferedImage image) { try { return tesseract.doOCR(image); } catch (TesseractException e) { return null; } } OCRUtil(); @Contract(pure = true) String ocrCalcCaptcha(@NotNull BufferedImage image); static final int SINGLE_LINE_MODE; }
@Test public void ocrCalcCaptcha() throws Exception { OCRUtil util = new OCRUtil(); List<String> excepted = Files.readAllLines(Paths.get( getClass().getResource("/captcha/excepted.txt").toURI())); for (int i = 0; i < 50;i++) { String str = util.ocrCalcCaptcha(ImageIO.read( getClass().getResource("/captcha/captcha" + i + ".png"))); System.out.println(str.trim()); assertEquals(excepted.get(i).trim(), str.trim()); } }