Could not initialize class net.sourceforge.tess4j.TessAPI
课程设计
1
我需要开发一个图片识别的功能,使用tess4j进行图片识别,window环境正常。使用docker将springBoot项目部署到linux服务器上,功能就用不了了,我在linux系统安装了leptonica、tesseract,也没有成功。应该如何使用tess4j?
Caused by: java.lang.NoClassDefFoundError: Could not initialize class net.sourceforge.tess4j.TessAPI
at net.sourceforge.tess4j.Tesseract.init(Tesseract.java:379)
at net.sourceforge.tess4j.Tesseract.doOCR(Tesseract.java:292)
at net.sourceforge.tess4j.Tesseract.doOCR(Tesseract.java:275)
at net.sourceforge.tess4j.Tesseract.doOCR(Tesseract.java:256)
at net.sourceforge.tess4j.Tesseract.doOCR(Tesseract.java:240)
at com.csg.sdc.admin.backend.cgls.msa.ValidImageUtil.parseValidImage(ValidImageUtil.java:41)
at com.csg.sdc.admin.backend.cgls.msa.ValidImageUtil.getValidImageString(ValidImageUtil.java:26)
at com.csg.sdc.admin.backend.cgls.msa.CertUtil.crew(CertUtil.java:60)
at com.csg.sdc.admin.backend.cgls.msa.Cert.search(Cert.java:45)
at com.csg.sdc.admin.backend.cgls.service.EmpInfoService.getEmpInfoCert(EmpInfoService.java:673)
at com.csg.sdc.admin.backend.cgls.web.EmpInfoController.getEmpInfoCert(EmpInfoController.java:96)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
我应该怎么配置、才能在linux系统正确的部署运行springboot项目的tess4j图片识别功能?
-
相关的代码
public static String getValidImageString(File imgFile) { if (imgFile == null) { return null; } else { try { File rfile = cleanLinesInImage(imgFile); BufferedImage textImage = ImageIO.read(rfile); return parseValidImage(textImage); } catch (IOException var3) { var3.printStackTrace(); return null; } } } public static String parseValidImage(BufferedImage img) { Tesseract instance = new Tesseract(); try { instance.setDatapath(ResourceUtils.getFile("classpath:tessdata").getAbsolutePath()); instance.setTessVariable("tessedit_char_whitelist", "23456789abcdefghjkmnpqrstuvwxyzABCDEFGHIJKLMNPQRSTUVWXYZ"); return instance.doOCR(img).trim().replaceAll("[^0-9a-zA-Z]*", ""); } catch (Exception e) { e.printStackTrace(); }return null; }
服务器上输入tesseract 命令,显示结果,应该是安装成功的。
发表回复