Documentation
¶
Overview ¶
Package ocr provides a vendor-agnostic OCR (Optical Character Recognition) abstraction for ling-base. Cloud OCR providers (Aliyun, AWS, Azure, Baidu, Google, QCloud) implement the Provider interface and self-register via RegisterProvider.
The core package has zero external dependencies. Optional integrations live in sub-modules (e.g. ocr/aliyun, ocr/aws).
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrNoProvider = fmt.Errorf("no OCR provider registered")
ErrNoProvider is returned when no OCR provider is configured.
Functions ¶
func RegisterProvider ¶
RegisterProvider registers an OCR provider under the given driver name. The last registration wins. Passing nil is a no-op.
func RegisteredDrivers ¶
func RegisteredDrivers() []string
RegisteredDrivers returns the names of all registered OCR providers.
func SetProvider ¶
func SetProvider(p Provider)
SetProvider sets the active global OCR provider. Passing nil clears the active provider.
func SetProviderByDriver ¶
SetProviderByDriver selects an already-registered provider by driver name as the active OCR provider. Returns an error if no provider is registered under that name.
Types ¶
type Options ¶
type Options struct {
// Language is a BCP-47 or provider-specific language hint (e.g. "zh", "en", "auto").
Language string
// Extra allows passing provider-specific parameters not covered by the struct.
Extra map[string]any
}
Options controls provider-specific behavior (language hints, etc.).
type Provider ¶
type Provider interface {
// Name returns the provider identifier (e.g. "aliyun", "qcloud", "google").
Name() string
// Recognize sends image bytes to the cloud OCR API and returns extracted text.
Recognize(ctx context.Context, imageBytes []byte, opts *Options) (string, error)
}
Provider is the interface that cloud OCR backends implement. Each provider calls a real cloud API to extract text from image bytes.
func GetProvider ¶
func GetProvider() Provider
GetProvider returns the currently active OCR provider, or nil if none is set.