Java Tesseract导致JVM崩溃
我正在致力于将OCR功能集成到我们的应用程序中。目前,每当我运行doOCr方法时,JVM就会崩溃,整个应用程序都会停止。我检查并发现,但答案是非常不清楚的,因为它只是告诉创建bean,但为什么,是未知的。有什么想法吗?多谢各位 代码:Java Tesseract导致JVM崩溃,java,tesseract,tess4j,Java,Tesseract,Tess4j,我正在致力于将OCR功能集成到我们的应用程序中。目前,每当我运行doOCr方法时,JVM就会崩溃,整个应用程序都会停止。我检查并发现,但答案是非常不清楚的,因为它只是告诉创建bean,但为什么,是未知的。有什么想法吗?多谢各位 代码: public synchronized String testOcr(String fileLocation, int attachId) { try { File imageFile = new File(fileLocati
public synchronized String testOcr(String fileLocation, int attachId) {
try {
File imageFile = new File(fileLocation);
BufferedImage img = ImageIO.read(imageFile);
String identifier = String.valueOf(new BigInteger(130, random).toString(32));
String blackAndWhiteImage = previewPath + identifier + ".png";
File outputfile = new File(blackAndWhiteImage);
BufferedImage bufferedImage = BitmapImageUtil.convertToGrayscale(img, new Dimension(img.getWidth(), img.getHeight()));
bufferedImage = Scalr.resize(bufferedImage,img.getWidth()*2,img.getHeight()*2);
ITesseract instance = Tesseract.getInstance();
synchronized (instance) {
// Point to one folder above tessdata directory, must contain training data
instance.setDatapath("/usr/share/tesseract-ocr/");
// ISO 693-3 standard
instance.setLanguage("deu");
String result = instance.doOCR(outputfile);
//System.out.println("Result is "+result);
result = result.replaceAll("[^a-zA-Z0-9öÖäÄüÜß@\\s]", "");
Files.delete(new File(blackAndWhiteImage).toPath());
GroupAttachments groupAttachments = this.groupAttachmentsDAO.getAttachmenById(attachId);
if (groupAttachments != null) {
saveIndexes(result, groupAttachments.getFileName(), null, groupAttachments.getGroupId(), false, attachId);
}
return result;
}
} catch (Exception ignored) {
}
return null;
}