mirror of
https://github.com/geekwenjie/SmartJavaAI.git
synced 2026-09-12 20:58:51 +00:00
- 新增OCR文字识别模块:支持最新 PP-OCRv5
- OCR文本识别:支持文字方向检测与自动校正
This commit is contained in:
@@ -6,7 +6,7 @@
|
||||
<parent>
|
||||
<groupId>cn.smartjavaai</groupId>
|
||||
<artifactId>smartjavaai-parent</artifactId>
|
||||
<version>1.0.14</version>
|
||||
<version>1.0.15</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>smartjavaai-ocr</artifactId>
|
||||
@@ -20,7 +20,7 @@
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<version>1.0.14</version>
|
||||
<version>1.0.15</version>
|
||||
<name>smartjavaai-ocr</name>
|
||||
<description>SmartJavaAI</description>
|
||||
<url>https://github.com/geekwenjie/SmartJavaAI</url>
|
||||
|
||||
@@ -47,6 +47,7 @@ import java.nio.file.Paths;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* PPOCRMobileV2Model 方向分类模型
|
||||
@@ -177,13 +178,12 @@ public class PPOCRMobileV2Model implements OcrDirectionModel {
|
||||
if (subImg.getHeight() * 1.0 / subImg.getWidth() > 1.5) {
|
||||
//旋转图片90度
|
||||
subImg = OcrUtils.rotateImg(manager, subImg);
|
||||
//ImageUtils.saveImage(subImg, i + "rotate.png", "build/output");
|
||||
//检测方向
|
||||
directionInfo = predictor.predict(subImg);
|
||||
if (directionInfo.getName().equalsIgnoreCase("Rotate")) {
|
||||
angle = "90";
|
||||
} else {
|
||||
angle = "270";
|
||||
} else {
|
||||
angle = "90";
|
||||
}
|
||||
}else{ //横向
|
||||
directionInfo = predictor.predict(subImg);
|
||||
|
||||
@@ -48,10 +48,7 @@ import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
/**
|
||||
@@ -158,8 +155,10 @@ public class PpOCRV5RecModel implements OcrCommonRecModel {
|
||||
for (OcrItem ocrItem : ocrItemList){
|
||||
//放射变换+裁剪
|
||||
Image subImage = OcrUtils.transformAndCrop(srcMat, ocrItem.getOcrBox());
|
||||
//ImageUtils.saveImage(subImage, UUID.randomUUID().toString() + "_aaa.png", "build/output");
|
||||
//纠正文本框
|
||||
subImage = OcrUtils.rotateImg(subImage, ocrItem.getAngle());
|
||||
//ImageUtils.saveImage(subImage, UUID.randomUUID().toString() + "_bbb.png", "build/output");
|
||||
//识别
|
||||
String name = predictor.predict(subImage);
|
||||
ocrItem.setText(name);
|
||||
|
||||
Reference in New Issue
Block a user