我使用Tes4j从图像pdf中提取文本。 这里涉及两个步骤: 1)将pdf转换为图像:
PdfUtilities.convertPdf2Png(inputfilepath);
这没有任何问题。 2)从图像中提取文本:
try {
if(imgName.endsWith(".png")){
ITesseract instance = new Tesseract();
instance.setDatapath("tessdataPath");
extractedData= instance.doOCR(Image);
}
catch(Exception e2){
System.out.println("exception:"+e2.getMessage());
}
}
}
执行此操作时,我会获得特定图像文件的异常。
Exception in thread "main" java.lang.Error: Invalid memory access
at com.sun.jna.Native.invokePointer(Native Method)
at com.sun.jna.Function.invokePointer(Function.java:470)
at com.sun.jna.Function.invoke(Function.java:404)
at com.sun.jna.Function.invoke(Function.java:315)
at com.sun.jna.Library$Handler.invoke(Library.java:212)
at com.sun.proxy.$Proxy1.TessBaseAPIGetUTF8Text(Unknown Source)
at net.sourceforge.tess4j.Tesseract.getOCRText(Unknown Source)
at net.sourceforge.tess4j.Tesseract.doOCR(Unknown Source)
at net.sourceforge.tess4j.Tesseract.doOCR(Unknown Source)
at net.sourceforge.tess4j.Tesseract.doOCR(Unknown Source)
at com.tcs.textExtraction.ImgToText.imagetoText(ImgToText.java:109)
at com.tcs.textExtraction.ImgToText.main(ImgToText.java:31)
split_pt >0 && split_pt < word->chopped_word->NumBlobs():Error:Assert failed:in file ..\..\ccmain\tfacepp.cpp, line 186
我已经包括以下罐子: jna.jar,log4j的-1.2.17.jar,PDFBOX-1.8.13.jar,tess4j.jar,共享记录-1.1.3.jar,fontbox-1.8.13.jar,ghost4j-0.5.1.jar, iText的 - 2.1.7.jar,jai_imageio.jar 我的tessdata有以下文件: pdf.ttf,pdf.ttx,eng.traineddata,osd.traineddata