diff --git a/backend/internal/modules/chat/qrcode.go b/backend/internal/modules/chat/qrcode.go index 23c2e5e..610a87b 100644 --- a/backend/internal/modules/chat/qrcode.go +++ b/backend/internal/modules/chat/qrcode.go @@ -23,7 +23,7 @@ const ( qrCodeOCRJobURLConfigKey = "integration.paddle_ocr_job_url" qrCodeOCRModelConfigKey = "integration.paddle_ocr_model" defaultQrCodeOCRJobURL = "https://paddleocr.aistudio-app.com/api/v2/ocr/jobs" - defaultQrCodeOCRModel = "PaddleOCR-VL-1.6" + defaultQrCodeOCRModel = "PP-OCRv6" ) var ( diff --git a/backend/internal/modules/chat/qrcode_ocr.go b/backend/internal/modules/chat/qrcode_ocr.go index 6e4c225..d7322e9 100644 --- a/backend/internal/modules/chat/qrcode_ocr.go +++ b/backend/internal/modules/chat/qrcode_ocr.go @@ -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) diff --git a/backend/internal/modules/chat/qrcode_ocr_test.go b/backend/internal/modules/chat/qrcode_ocr_test.go index 75f02f7..2f6f36e 100644 --- a/backend/internal/modules/chat/qrcode_ocr_test.go +++ b/backend/internal/modules/chat/qrcode_ocr_test.go @@ -222,3 +222,20 @@ func pngHeader(width, height uint32) []byte { binary.Write(&result, binary.BigEndian, checksum) return result.Bytes() } + +func TestCollectPaddleOCRJSONLTextSupportsPPOCRv6(t *testing.T) { + rawJSONL := `{"result":{"ocrResults":[{"prunedResult":{"rec_texts":["火爆出租-778群","扫码加入群聊"]},"ocrImage":"https://example.com/ocr.jpg","inputImage":"https://example.com/in.jpg"}]}}` + text := collectPaddleOCRJSONLText(rawJSONL) + if !strings.Contains(text, "火爆出租-778群") || !strings.Contains(text, "扫码加入群聊") { + t.Fatalf("collected text = %q, expected recognized group texts", text) + } + if strings.Contains(text, "ocr.jpg") || strings.Contains(text, "in.jpg") { + t.Fatalf("collected text = %q, should not include image URLs", text) + } + + candidates := parseQrCodeGroupNameCandidates(text) + if len(candidates) == 0 || candidates[0] != "火爆出租-778群" { + t.Fatalf("candidates = %v, want 火爆出租-778群 as first candidate", candidates) + } +} + diff --git a/backend/internal/modules/systemconfig/repository.go b/backend/internal/modules/systemconfig/repository.go index a5850f9..32cd4ad 100644 --- a/backend/internal/modules/systemconfig/repository.go +++ b/backend/internal/modules/systemconfig/repository.go @@ -47,7 +47,7 @@ var defaultConfigs = []defaultConfig{ {Key: "chat.renter_retention_days_after_order_end", Value: "5", Description: "订单结束后租客保留在发布群的天数(3-7)"}, {Key: "integration.paddle_ocr_token", Value: "", Description: "PaddleOCR API Token,用于二维码群名自动识别"}, {Key: "integration.paddle_ocr_job_url", Value: "https://paddleocr.aistudio-app.com/api/v2/ocr/jobs", Description: "PaddleOCR 异步任务接口地址"}, - {Key: "integration.paddle_ocr_model", Value: "PaddleOCR-VL-1.6", Description: "PaddleOCR 识别模型"}, + {Key: "integration.paddle_ocr_model", Value: "PP-OCRv6", Description: "PaddleOCR 识别模型(默认 PP-OCRv6,支持 PaddleOCR-VL-1.6 等)"}, {Key: homeAnnouncementsConfigKey, Value: defaultHomeAnnouncementsConfigValue(), Description: "移动端首页公告 JSON 数组"}, {Key: homeBannersConfigKey, Value: defaultHomeBannersConfigValue(), Description: "移动端首页轮播图 JSON 数组"}, {Key: awRecycleConfigKey, Value: defaultAWRecycleConfigValue(), Description: "首页 AW炫彩回收入口配置 JSON(标题/副标题/展示图片)"}, diff --git a/backend/migrations/000065_default_paddle_ocr_model_v6.sql b/backend/migrations/000065_default_paddle_ocr_model_v6.sql new file mode 100644 index 0000000..53a70a3 --- /dev/null +++ b/backend/migrations/000065_default_paddle_ocr_model_v6.sql @@ -0,0 +1,13 @@ +-- +goose Up +-- +goose StatementBegin +UPDATE system_configs +SET value = 'PP-OCRv6', description = 'PaddleOCR 识别模型(默认 PP-OCRv6,支持 PaddleOCR-VL-1.6 等)' +WHERE `key` = 'integration.paddle_ocr_model' AND (value = 'PaddleOCR-VL-1.6' OR value = '' OR value IS NULL); +-- +goose StatementEnd + +-- +goose Down +-- +goose StatementBegin +UPDATE system_configs +SET value = 'PaddleOCR-VL-1.6', description = 'PaddleOCR 识别模型' +WHERE `key` = 'integration.paddle_ocr_model' AND value = 'PP-OCRv6'; +-- +goose StatementEnd diff --git a/frontend/src/features/admin/views/AdminSystemConfigsView.vue b/frontend/src/features/admin/views/AdminSystemConfigsView.vue index efcaf4b..9273f7c 100644 --- a/frontend/src/features/admin/views/AdminSystemConfigsView.vue +++ b/frontend/src/features/admin/views/AdminSystemConfigsView.vue @@ -145,7 +145,7 @@ const paddleOcrJobUrlConfig = computed(() => ) ) const paddleOcrModelConfig = computed(() => - systemConfigByKey('integration.paddle_ocr_model', 'PaddleOCR-VL-1.6', 'PaddleOCR 识别模型') + systemConfigByKey('integration.paddle_ocr_model', 'PP-OCRv6', 'PaddleOCR 识别模型') ) const regularConfigs = computed(() => diff --git a/frontend/src/shared/utils/systemConfigOptions.ts b/frontend/src/shared/utils/systemConfigOptions.ts index 3bc1851..675b4ca 100644 --- a/frontend/src/shared/utils/systemConfigOptions.ts +++ b/frontend/src/shared/utils/systemConfigOptions.ts @@ -58,7 +58,10 @@ export const systemConfigSelectOptions: Record = { { label: '5 天', value: '5' }, { label: '7 天', value: '7' }, ], - 'integration.paddle_ocr_model': [{ label: 'PaddleOCR-VL-1.6', value: 'PaddleOCR-VL-1.6' }], + 'integration.paddle_ocr_model': [ + { label: 'PP-OCRv6(推荐,低延迟少排队)', value: 'PP-OCRv6' }, + { label: 'PaddleOCR-VL-1.6', value: 'PaddleOCR-VL-1.6' }, + ], } export function getSystemConfigSelectOptions(key: string) {