feat: OCR 服务 + 会议材料模块
ry-ocr/ (新)
本地发票识别微服务 (PaddleOCR 3.x + FastAPI, 8801)
- QR 优先: 扫到二维码即取开票时间/发票号/金额; 没扫到/格式不合法直接判非发票, 不跑 OCR
- 配置 QR_FULL_OCR 控制快路径(false, 0.2s)还是全字段(true, 4.5s)
- /recognize/invoice (multipart) + /recognize/invoice/by-path (本地路径, 白名单) + /recognize/text
- is_invoice / from_qr / qr_raw / qr_error / error_code 字段
- 12 字段发票抽取 (regex + 启发式, 左右主体识别)
- 超时保护 (15s 单页 / 60s 总流程) + PaddleOCR 单例 + ThreadPoolExecutor
ry-api/ruoyi-business/
- pom.xml: 加 hutool-http/json/core 5.8.27, lombok 1.18.30 (OcrClient @Slf4j 所需)
- ocr/: OcrClient + InvoiceResult/Fields/Line + ZipExtractor + InvoiceOcrScheduler
- oss/: OssUploader + OssConfMeta (OCR 识别后重传 OSS)
- config/: OcrConfig + OcrExecutorConfig (后台线程池)
- service/impl/InvoiceOcrService: 后台提交 OCR, ZIP 路径解压识别, 替换场景先清旧
- 会议材料 CRUD 全套 (BizMeetingAuditLog/Executor/Invoice/Material/Supervisor):
controller + service + mapper + domain + xml
ry-vue3/
- MeetingDetail.vue (新建): 会议详情页 (含评分维度章节, 改只读)
- Meetings.vue / OssFileUploader.vue / router / Login.vue: 适配新字段
ry-api/ruoyi-admin/
- RuoYiApplication.java + application.yml: 启用 @Async 异步支持
_self/
- manager_meetings.md / manager_meeting_detail.md: 文档
This commit is contained in:
@@ -0,0 +1,47 @@
|
||||
"""图像预处理:自动旋转、放大、去噪"""
|
||||
from __future__ import annotations
|
||||
|
||||
from pathlib import Path
|
||||
|
||||
import cv2
|
||||
import numpy as np
|
||||
|
||||
|
||||
def auto_rotate(img_path: str | Path) -> Path:
|
||||
"""基于方向检测的简易旋转(> 阈值倾斜就转 90°)
|
||||
|
||||
说明:发票多为横向,此处只处理 0/90/180/270 四方向,
|
||||
复杂倾斜交给 PaddleOCR 自带的 textline orientation。
|
||||
"""
|
||||
p = Path(img_path)
|
||||
img = cv2.imread(str(p))
|
||||
if img is None:
|
||||
return p
|
||||
|
||||
h, w = img.shape[:2]
|
||||
# 横图宽 > 高 * 1.2,认为方向正确;否则旋转
|
||||
if h > w * 1.2:
|
||||
rotated = cv2.rotate(img, cv2.ROTATE_90_CLOCKWISE)
|
||||
out = p.with_name(f"{p.stem}_rot.png")
|
||||
cv2.imwrite(str(out), rotated)
|
||||
return out
|
||||
return p
|
||||
|
||||
|
||||
def enhance(img_path: str | Path) -> Path:
|
||||
"""轻度增强:灰度 + 自适应二值化(对手机拍的发票有帮助)"""
|
||||
p = Path(img_path)
|
||||
img = cv2.imread(str(p))
|
||||
if img is None:
|
||||
return p
|
||||
|
||||
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
|
||||
# 弱增强:只对低对比度图做二值化
|
||||
if gray.std() < 50:
|
||||
binary = cv2.adaptiveThreshold(
|
||||
gray, 255, cv2.ADAPTIVE_THRESH_GAUSSIAN_C, cv2.THRESH_BINARY, 31, 10
|
||||
)
|
||||
out = p.with_name(f"{p.stem}_enh.png")
|
||||
cv2.imwrite(str(out), binary)
|
||||
return out
|
||||
return p
|
||||
Reference in New Issue
Block a user