@Test
  public void testFolderExtraction() {

    File tessDataFolder = null;

    try {

      /** Loads the image from resources. */
      String filename = String.format("%s/%s", "/test-data", "eurotext.pdf");
      URL defaultImage = getClass().getResource(filename);
      File imageFile = new File(defaultImage.toURI());

      /** Extracts <code>tessdata</code> folder into a temp folder. */
      logger.info("Loading the tessdata folder into a temporary folder.");
      tessDataFolder = LoadLibs.extractTessResources("tessdata");

      /** Gets tesseract instance and sets data path. */
      ITesseract instance = new Tesseract();

      if (tessDataFolder != null) {
        logger.info(tessDataFolder.getAbsolutePath());
        instance.setDatapath(tessDataFolder.getAbsolutePath());
        instance.setLanguage("por");
      }

      /** Performs OCR on the image. */
      String result = instance.doOCR(imageFile);
      logger.info(result);

    } catch (TesseractException e) {
      logger.error(e.getMessage());
      logger.error(e.getMessage(), e);
    } catch (URISyntaxException e) {
      logger.error(e.getMessage(), e);
    }

    // checks if tessdata folder exists
    assertTrue(tessDataFolder != null && tessDataFolder.exists());
  }
Example #2
0
 @Before
 public void setUp() {
   instance = new Tesseract();
   instance.setDatapath(new File(datapath).getPath());
 }