我正在努力在我们的应用程序中集成OCR功能。目前,每当我运行doOCr方法时,JVM崩溃并停止整个应用程序。我检查了一下,发现了this,但答案很清楚,因为它只是告诉创建bean,但是为了什么,是未知的。有任何想法吗?谢谢。
COde:
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;
}