- 新增 语音识别模块,集成 OpenAI 开源的 Whisper 和 Vosk

- 修复 质量评估模型的 Bug
- 修复 OCR 模块 recognizeAndDraw 方法的 Bug
- 修复 车牌识别在未检测到车牌时的报错问题
- 优化 OCR 表格识别功能,新增导出方式
This commit is contained in:
dengwenjie
2025-08-11 10:38:50 +08:00
parent 9b6f5ea9a1
commit 166f0f9d20
46 changed files with 1325 additions and 146 deletions

View File

@@ -6,7 +6,7 @@
<parent>
<groupId>cn.smartjavaai</groupId>
<artifactId>smartjavaai-parent</artifactId>
<version>1.0.22</version>
<version>1.0.23</version>
</parent>
<artifactId>smartjavaai-ocr</artifactId>
@@ -42,7 +42,7 @@
</dependency>
</dependencies>
<version>1.0.22</version>
<version>1.0.23</version>
<name>smartjavaai-ocr</name>
<description>SmartJavaAI</description>
<url>https://github.com/geekwenjie/SmartJavaAI</url>

View File

@@ -36,6 +36,7 @@ import java.awt.image.BufferedImage;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.IOException;
import java.io.OutputStream;
import java.nio.file.Paths;
import java.util.*;
import java.util.List;
@@ -180,6 +181,25 @@ public class TableRecognizer {
ImageUtils.saveImage(image, savePath);
}
/**
* 绘制表格
* @param tableStructureResult
* @param image
* @return
*/
public BufferedImage drawTable(TableStructureResult tableStructureResult, BufferedImage image){
if(Objects.isNull(tableStructureResult) || CollectionUtils.isEmpty(tableStructureResult.getTableTagList())){
throw new OcrException("表格结构为空");
}
for (int i = 0; i < tableStructureResult.getOcrItemList().size(); i++){
OcrItem item = tableStructureResult.getOcrItemList().get(i);
DetectionRectangle detectionRectangle = item.getOcrBox().toDetectionRectangle();
ImageUtils.drawImageRectWithText(image, detectionRectangle, i + "", Color.RED);
}
return image;
}
/**
* 删除 HTML 中第一个 <style> ... </style> 段落
* @param html 原始 HTML
@@ -200,17 +220,34 @@ public class TableRecognizer {
return html.substring(0, styleStart) + html.substring(styleEnd);
}
/**
* 导出 Excel
* @param html
* @param out
*/
public void exportExcel(String html, OutputStream out){
String content = removeStyleBlock(html);
content = content.replace("<html><body>", "");
content = content.replace("</body></html>", "");
try (HSSFWorkbook workbook = ConvertHtml2Excel.table2Excel(content)){
workbook.write(out);
out.flush();
} catch (Exception e) {
throw new OcrException("导出excel失败请检查表结构是否识别正确");
}
}
/**
* 导出 Excel
* @param html
* @param savePath
*/
public void exportExcel(String html, String savePath){
try {
String content = removeStyleBlock(html);
content = content.replace("<html><body>", "");
content = content.replace("</body></html>", "");
HSSFWorkbook workbook = ConvertHtml2Excel.table2Excel(content);
String content = removeStyleBlock(html);
content = content.replace("<html><body>", "");
content = content.replace("</body></html>", "");
try (HSSFWorkbook workbook = ConvertHtml2Excel.table2Excel(content)){
workbook.write(new File(savePath));
} catch (Exception e) {
throw new OcrException("导出excel失败请检查表结构是否识别正确");