|
@@ -0,0 +1,40 @@
|
|
|
|
|
+package space.anyi.amountVerification;
|
|
|
|
|
+
|
|
|
|
|
+/**
|
|
|
|
|
+ * @ProjectName: amount-verification
|
|
|
|
|
+ * @FileName: MainServer
|
|
|
|
|
+ * @Author: 杨逸
|
|
|
|
|
+ * @Data:2025/11/28 21:11
|
|
|
|
|
+ * @Description:
|
|
|
|
|
+ */
|
|
|
|
|
+
|
|
|
|
|
+import net.sourceforge.tess4j.Tesseract;
|
|
|
|
|
+import net.sourceforge.tess4j.TesseractException;
|
|
|
|
|
+import java.io.File;
|
|
|
|
|
+
|
|
|
|
|
+public class MainServer {
|
|
|
|
|
+ public static void main(String[] args) throws TesseractException {
|
|
|
|
|
+ long start = System.currentTimeMillis();
|
|
|
|
|
+ System.out.println("开始OCR文字识图,请稍后...");
|
|
|
|
|
+ //加载要识别的图片
|
|
|
|
|
+ File image = new File("C:\\Users\\杨逸\\Documents\\amount-verification\\src\\main\\resources\\1.png");
|
|
|
|
|
+ //设置配置文件夹微视、识别语言、识别模式
|
|
|
|
|
+ Tesseract tesseract = new Tesseract();
|
|
|
|
|
+ //File tessdataFolder = new File("classpath:tessdata");
|
|
|
|
|
+ //tesseract.setDatapath("D:\\tools\\tessdata\\best");
|
|
|
|
|
+ tesseract.setDatapath("D:\\tools\\tessdata\\fast");
|
|
|
|
|
+ //设置识别语言为中文简体,(如果要设置为英文可改为"eng")
|
|
|
|
|
+ tesseract.setLanguage("chi_sim");
|
|
|
|
|
+ //使用 OSD 进行自动页面分割以进行图像处理
|
|
|
|
|
+ //tesseract.setPageSegMode(1);
|
|
|
|
|
+ //设置引擎模式是神经网络LSTM引擎
|
|
|
|
|
+ //tesseract.setOcrEngineMode(1);
|
|
|
|
|
+ //开始识别整张图片中的文字
|
|
|
|
|
+ String result = tesseract.doOCR(image);
|
|
|
|
|
+ long time = System.currentTimeMillis()-start;
|
|
|
|
|
+ System.out.println("识别结束,耗时:"+time+" 毫秒,识别结果如下:");
|
|
|
|
|
+ System.out.println();
|
|
|
|
|
+ System.out.println(result);
|
|
|
|
|
+ }
|
|
|
|
|
+}
|
|
|
|
|
+
|