Files
tyapi-server/internal/shared/ocr/ocr_interface.go

53 lines
1.8 KiB
Go
Raw Normal View History

2025-07-11 21:05:58 +08:00
package ocr
import (
"context"
2025-07-13 16:36:20 +08:00
"tyapi-server/internal/application/certification/dto/responses"
2025-07-11 21:05:58 +08:00
)
// OCRService OCR识别服务接口
type OCRService interface {
// 识别营业执照
2025-07-13 16:36:20 +08:00
RecognizeBusinessLicense(ctx context.Context, imageBytes []byte) (*responses.BusinessLicenseResult, error)
2025-07-11 21:05:58 +08:00
// 识别身份证
2025-07-13 16:36:20 +08:00
RecognizeIDCard(ctx context.Context, imageBytes []byte, side string) (*responses.IDCardResult, error)
2025-07-11 21:05:58 +08:00
// 通用文字识别
2025-07-13 16:36:20 +08:00
RecognizeGeneralText(ctx context.Context, imageBytes []byte) (*responses.GeneralTextResult, error)
// 从URL识别图片
RecognizeFromURL(ctx context.Context, imageURL string, ocrType string) (interface{}, error)
// 验证营业执照结果
ValidateBusinessLicense(result *responses.BusinessLicenseResult) error
// 验证身份证结果
ValidateIDCard(result *responses.IDCardResult) error
2025-07-11 21:05:58 +08:00
}
2025-07-13 16:36:20 +08:00
// IDCardInfo 身份证识别信息(保留兼容性)
2025-07-11 21:05:58 +08:00
type IDCardInfo struct {
Name string `json:"name"` // 姓名
IDCardNumber string `json:"id_card_number"` // 身份证号
Gender string `json:"gender"` // 性别
Nation string `json:"nation"` // 民族
Birthday string `json:"birthday"` // 出生日期
Address string `json:"address"` // 住址
IssuingAgency string `json:"issuing_agency"` // 签发机关
ValidPeriod string `json:"valid_period"` // 有效期限
Confidence float64 `json:"confidence"` // 识别置信度
}
2025-07-13 16:36:20 +08:00
// GeneralTextResult 通用文字识别结果(保留兼容性)
2025-07-11 21:05:58 +08:00
type GeneralTextResult struct {
Words []TextLine `json:"words"` // 识别的文字行
Confidence float64 `json:"confidence"` // 整体置信度
}
// TextLine 文字行
type TextLine struct {
Text string `json:"text"` // 文字内容
Confidence float64 `json:"confidence"` // 置信度
}