|
@@ -4,8 +4,7 @@ import com.alibaba.excel.EasyExcel;
|
|
|
import com.alibaba.excel.ExcelWriter;
|
|
import com.alibaba.excel.ExcelWriter;
|
|
|
import com.alibaba.excel.read.listener.PageReadListener;
|
|
import com.alibaba.excel.read.listener.PageReadListener;
|
|
|
import com.alibaba.excel.write.metadata.WriteSheet;
|
|
import com.alibaba.excel.write.metadata.WriteSheet;
|
|
|
-import io.github.mymonstercat.Model;
|
|
|
|
|
-import io.github.mymonstercat.ocr.InferenceEngine;
|
|
|
|
|
|
|
+import io.github.hzkitty.RapidOCR;
|
|
|
import javafx.application.Application;
|
|
import javafx.application.Application;
|
|
|
import javafx.application.Platform;
|
|
import javafx.application.Platform;
|
|
|
import javafx.geometry.Insets;
|
|
import javafx.geometry.Insets;
|
|
@@ -28,6 +27,7 @@ import space.anyi.amountVerification.model.InputModel;
|
|
|
import space.anyi.amountVerification.model.OutputErrorModel;
|
|
import space.anyi.amountVerification.model.OutputErrorModel;
|
|
|
import space.anyi.amountVerification.model.OutputModel;
|
|
import space.anyi.amountVerification.model.OutputModel;
|
|
|
|
|
|
|
|
|
|
+import javax.imageio.ImageIO;
|
|
|
import java.awt.image.BufferedImage;
|
|
import java.awt.image.BufferedImage;
|
|
|
import java.io.File;
|
|
import java.io.File;
|
|
|
import java.io.IOException;
|
|
import java.io.IOException;
|
|
@@ -98,15 +98,13 @@ public class App extends Application {
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* OCR使用的对象
|
|
* OCR使用的对象
|
|
|
- * @see InferenceEngine
|
|
|
|
|
|
|
+ * @see RapidOCR
|
|
|
*/
|
|
*/
|
|
|
- private final InferenceEngine engineOCR;
|
|
|
|
|
|
|
+ private final RapidOCR rapidOCR;
|
|
|
|
|
|
|
|
public App() {
|
|
public App() {
|
|
|
- //配置临时目录,用于存放OCR模型
|
|
|
|
|
- System.setProperty("java.io.tmpdir", System.getenv("user.dir") + "\\temp");
|
|
|
|
|
//初始化OCR使用的对象
|
|
//初始化OCR使用的对象
|
|
|
- this.engineOCR = InferenceEngine.getInstance(Model.ONNX_PPOCR_V4);
|
|
|
|
|
|
|
+ this.rapidOCR = new RapidOCR();
|
|
|
//初始化匹配金额的正则表达式对象
|
|
//初始化匹配金额的正则表达式对象
|
|
|
String regex = "理赔金额合计[^\\d]{1,2}[¥¥#Y半]?(?<money>\\d+\\.\\d{2})";
|
|
String regex = "理赔金额合计[^\\d]{1,2}[¥¥#Y半]?(?<money>\\d+\\.\\d{2})";
|
|
|
this.pattern = Pattern.compile(regex);
|
|
this.pattern = Pattern.compile(regex);
|
|
@@ -464,11 +462,10 @@ public class App extends Application {
|
|
|
BufferedImage bufferedImage = null;
|
|
BufferedImage bufferedImage = null;
|
|
|
try {
|
|
try {
|
|
|
//使用RapidOCR进行识别
|
|
//使用RapidOCR进行识别
|
|
|
- text = engineOCR.runOcr(workOrderFile.getAbsolutePath()).getStrRes().trim();
|
|
|
|
|
//开始识别整张图片中的文字
|
|
//开始识别整张图片中的文字
|
|
|
- //bufferedImage = ImageIO.read(workOrderFile);
|
|
|
|
|
|
|
+ bufferedImage = ImageIO.read(workOrderFile);
|
|
|
//直接处理二进制数据,避免因为文件扩展名错误导致的处理失败
|
|
//直接处理二进制数据,避免因为文件扩展名错误导致的处理失败
|
|
|
- //text = tesseract.doOCR(bufferedImage);
|
|
|
|
|
|
|
+ text = rapidOCR.run(bufferedImage).getStrRes().trim();
|
|
|
log.debug("OCR解析{}到{}",workOrderFile.getAbsolutePath(),text);
|
|
log.debug("OCR解析{}到{}",workOrderFile.getAbsolutePath(),text);
|
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
|
log.warn("OCR解析{}失败,case:{}",workOrderFile.getAbsolutePath(),e.getMessage());
|
|
log.warn("OCR解析{}失败,case:{}",workOrderFile.getAbsolutePath(),e.getMessage());
|