I am using Tess4J in my project to extract text from an image (Using Eclipse IDE). I am getting the following error when I try run the OCR. Any suggestion?
Error: Exception in thread "main" java.lang.Error: Invalid memory access
Note: I have attached the image file which I've used
My Code:
package tesseractTraining;
import java.io.File;
import net.sourceforge.tess4j.*;
public class TesseractMainRunner {
public static void main(String[] args) {
File imageFile = new File("E:\\Tesseract\\Test Images\\sample.png");
Tesseract instance = new Tesseract();
try {
instance.setDatapath("C:\\Program Files (x86)\\Tesseract-OCR\\tessdata");
instance.setLanguage("eng");
String result = instance.doOCR(imageFile);
System.out.println(result);
} catch (TesseractException e) {
System.err.println(e.getMessage());
}
imageFile.exists();
}
}
--
You received this message because you are subscribed to the Google Groups "tesseract-ocr" group.
To unsubscribe from this group and stop receiving emails from it, send an email to tesseract-oc...@googlegroups.com.
To post to this group, send email to tesser...@googlegroups.com.
Visit this group at https://groups.google.com/group/tesseract-ocr.
To view this discussion on the web visit https://groups.google.com/d/msgid/tesseract-ocr/a384bae2-9580-4066-a0f0-9d90eacc50fd%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
<dependency>
<groupId>net.sourceforge.tess4j</groupId>
<artifactId>tess4j</artifactId>
<version>4.3.1</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>3.141.59</version>
</dependency>
File imgFile = findElement(captchaimgIdPath).getScreenshotAs(OutputType.FILE);
String pth = "C:\\Users\\username\\Downloads\\capthca1\\testcap.png"; //src/main/resources
Thread.sleep(2000);
FileHandler.copy(imgFile, new File(pth));
Thread.sleep(2000);
Tesseract cptcha = new Tesseract();
cptcha.setDatapath(pth);
cptcha.setLanguage("eng");
String text = cptcha.doOCR(new File(pth));
System.out.println(text);
String pth = "C:\\Users\\username\\Downloads\\capthca1\\testcap.png";
FileHandler.copy(imgFile, new File(pth));
cptcha.setDatapath(pth); <---- incorrect pth value