feat(ocr): 支持 PP-OCRv6 异步识别模型并设为默认,解决排队与高延迟问题
This commit is contained in:
@@ -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 (
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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(标题/副标题/展示图片)"},
|
||||
|
||||
@@ -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
|
||||
@@ -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(() =>
|
||||
|
||||
@@ -58,7 +58,10 @@ export const systemConfigSelectOptions: Record<string, SystemConfigOption[]> = {
|
||||
{ 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) {
|
||||
|
||||
Reference in New Issue
Block a user