ocr

package
v0.0.0-...-c1ba7d0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 10, 2026 License: AGPL-3.0 Imports: 28 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrUnknownProvider  = errors.New("unknown OCR provider")
	ErrUnavailable      = errors.New("OCR provider is unavailable")
	ErrUnsupportedImage = errors.New("unsupported OCR image format")
	ErrPermanent        = errors.New("OCR image cannot be recognized without changes")
)

Functions

func ValidateModels

func ValidateModels(directory string) error

ValidateModels 在导入和加载时校验配套配置,不接受自定义算子或外部权重。

Types

type PaddleConfig

type PaddleConfig struct {
	Library    string     `json:"library"`
	Worker     string     `json:"worker"`
	Directory  string     `json:"directory"`
	Thresholds Thresholds `json:"thresholds"`
}

PaddleConfig 指定一组检测和识别模型,Linux 使用原生辅助进程以兼容静态内核。

type PaddleProvider

type PaddleProvider struct {
	Config func() PaddleConfig
	// contains filtered or unexported fields
}

func (*PaddleProvider) Available

func (p *PaddleProvider) Available() bool

func (*PaddleProvider) Close

func (p *PaddleProvider) Close()

Close 释放模型会话,正在进行的识别完成后才会执行。

func (*PaddleProvider) Recognize

func (p *PaddleProvider) Recognize(ctx context.Context, path string) ([]map[string]string, error)

func (*PaddleProvider) Validate

func (p *PaddleProvider) Validate(ctx context.Context) error

Validate 加载两个原生会话,导入时拒绝无法执行的 ONNX 文件。

type Provider

type Provider interface {
	Available() bool
	Recognize(context.Context, string) ([]map[string]string, error)
}

Provider 只负责识别,结果存储和搜索索引由调用方统一维护。 结果保留字符串列,兼容现有 OCR HTTP 接口的 ocrJSON 字段。

type ProviderID

type ProviderID string
const (
	Tesseract ProviderID = "tesseract"
	PaddleOCR ProviderID = "paddleocr"
)

type Registry

type Registry struct {
	// contains filtered or unexported fields
}

Registry 串行调度识别,避免多个调用同时占用模型内存。

func NewRegistry

func NewRegistry() *Registry

func (*Registry) Available

func (r *Registry) Available(id ProviderID) bool

func (*Registry) Recognize

func (r *Registry) Recognize(ctx context.Context, id ProviderID, imagePath string) ([]map[string]string, error)

func (*Registry) Register

func (r *Registry) Register(id ProviderID, provider Provider) error

type Thresholds

type Thresholds struct {
	Detection   *float64 `json:"detection"`
	Box         *float64 `json:"box"`
	Recognition *float64 `json:"recognition"`
}

Thresholds 仅覆盖本次识别的后处理参数,空值保留模型检测配置和既有识别阈值。

func (Thresholds) Validate

func (t Thresholds) Validate() error

type WorkerRequest

type WorkerRequest struct {
	Config PaddleConfig `json:"config"`
	Image  string       `json:"image"`
}

Directories

Path Synopsis
cmd
ocr-worker command

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
⌂ 换网址