Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/332.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Tesseract导致JVM崩溃_Java_Tesseract_Tess4j - Fatal编程技术网

Java Tesseract导致JVM崩溃

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

我正在致力于将OCR功能集成到我们的应用程序中。目前,每当我运行doOCr方法时,JVM就会崩溃,整个应用程序都会停止。我检查并发现,但答案是非常不清楚的,因为它只是告诉创建bean,但为什么,是未知的。有什么想法吗?多谢各位

代码:

 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;
    }