feat(ocr): 支持 PP-OCRv6 异步识别模型并设为默认,解决排队与高延迟问题

This commit is contained in:
yml2213
2026-09-10 20:12:05 +08:00
parent 784ffb5f72
commit 7734f315ce
7 changed files with 51 additions and 5 deletions
+14 -1
View File
@@ -443,6 +443,7 @@ func (r *Repository) submitPaddleOCRJob(ctx context.Context, config *QrCodeOCRCo
optionalPayload, _ := json.Marshal(map[string]bool{
"useDocOrientationClassify": false,
"useDocUnwarping": false,
"useTextlineOrientation": false,
"useChartRecognition": false,
})
_ = writer.WriteField("optionalPayload", string(optionalPayload))
@@ -790,13 +791,25 @@ func collectPaddleOCRText(value any, texts *[]string) {
collectPaddleOCRText(item, texts)
}
case map[string]any:
// PP-OCRv6: prunedResult.rec_texts 包含检测并识别的文字列表
if recTexts, ok := v["rec_texts"].([]any); ok {
for _, item := range recTexts {
if text, ok := item.(string); ok && strings.TrimSpace(text) != "" {
*texts = append(*texts, text)
}
}
return
}
// PaddleOCR-VL: markdown.text 包含识别文本
if markdown, ok := v["markdown"].(map[string]any); ok {
if text, ok := markdown["text"].(string); ok && strings.TrimSpace(text) != "" {
*texts = append(*texts, text)
}
}
for key, item := range v {
if key == "images" || key == "outputImages" {
if key == "images" || key == "outputImages" || key == "ocrImage" || key == "inputImage" ||
key == "preprocessedImages" || key == "model_settings" || key == "text_det_params" ||
key == "logId" || key == "errorCode" || key == "errorMsg" || key == "dataInfo" {
continue
}
collectPaddleOCRText(item, texts)