ocr

package
v0.0.18 Latest Latest
Warning

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

Go to latest
Published: Jun 15, 2025 License: AGPL-3.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const FeatureTesseractEnabled = false

Variables

This section is empty.

Functions

This section is empty.

Types

type OCRProgress added in v0.0.10

type OCRProgress interface {
	// Receives updates with % completion from 0 to 100.
	// If noone reads from chanel, OCR is not blocked.
	// Chanel may not contain latest information if it is not readed fast.
	CompletionUpdates() chan uint8
	// Contains actual completion progress in % from 0 to 100.
	Completion() uint8
	// Wait until operation is fully completed and get final text.
	Text() (string, error)
}

Handles progress of the OCR

type Paddle added in v0.0.2

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

func NewPaddle added in v0.0.2

func NewPaddle(config PaddleConfig) *Paddle

func (*Paddle) IsMimeTypeSupported added in v0.0.2

func (p *Paddle) IsMimeTypeSupported(mimeType string) bool

func (*Paddle) OCR added in v0.0.2

func (p *Paddle) OCR(ctx context.Context, image io.Reader) (string, error)

func (*Paddle) OCRWithProgress added in v0.0.10

func (p *Paddle) OCRWithProgress(ctx context.Context, image io.Reader) OCRProgress

type PaddleConfig added in v0.0.2

type PaddleConfig struct {
	// HTTP client used to make requests to the server
	Client *http.Client
	// Server base URL. For example http://127.0.0.1:8884
	BaseURL string
	// List of language codes that should be recognized. More languages - more processing time.
	// Order matters. Primary language has to go first as it will act as fallback. By default it will be ["eng"]
	// Make sure languages are installed on the server because default OCR server has only several languages enabled by default.
	Languages []string `json:"languages"`
}

func DefaultPaddleConfig added in v0.0.2

func DefaultPaddleConfig() PaddleConfig

type Provider

type Provider interface {
	// Get text from image. Thread safe
	OCR(ctx context.Context, image io.Reader) (string, error)
	// Starts OCR in the background and returns hander to check progress updates.
	OCRWithProgress(ctx context.Context, image io.Reader) OCRProgress
	// Check if this provider supports specific mime type
	IsMimeTypeSupported(mimeType string) bool
}

Provides OCR functionality

type ProviderName

type ProviderName string

type Tesseract

type Tesseract struct {
}

func NewTesseract added in v0.0.2

func NewTesseract(config TesseractConfig) *Tesseract

func (*Tesseract) Destroy

func (p *Tesseract) Destroy() error

func (*Tesseract) Init

func (p *Tesseract) Init() error

func (*Tesseract) IsMimeTypeSupported

func (p *Tesseract) IsMimeTypeSupported(mimeType string) bool

func (*Tesseract) OCR

func (p *Tesseract) OCR(ctx context.Context, image io.Reader) (string, error)

func (*Tesseract) OCRWithProgress added in v0.0.10

func (p *Tesseract) OCRWithProgress(ctx context.Context, image io.Reader) OCRProgress

type TesseractConfig

type TesseractConfig struct {
	// List of language codes that should be recognized. More languages - more processing time. Order matters. Primary language has to go first as it will act as fallback. By default it will be ["eng"]
	Languages []string `json:"languages"`
	// Model to use while running tesseract. Default is `TesseractModelNormal`. Works only if `LoadCustomModels` option is set to True.
	ModelType TesseractModelType `json:"modelType"`
	// Load latest models from internet. If this is not selected, you have to manually install additional tesseract packages with models for specified languages.
	LoadCustomModels bool `json:"loadCustomModels"`
	// On startup, tesseract will download models from the internet and save them to specified location. Default is `./data/ocr/tesseract`
	ModelsFolder string `json:"modelsFolder"`
	// Variable to pass on tesseract initialization. For example you can pass {"load_system_dawg":"0"} to disable loading words list from the system
	//
	// Default is {"load_system_dawg": "0", "load_freq_dawg": "0", "load_punc_dawg": "0", "load_number_dawg": "0", "load_unambig_dawg": "0", "load_bigram_dawg": "0"}
	Variables map[string]string `json:"variables"`
	// Image formats supported by tessecart. Tesseract requires you to install third party libraries on the target machine to support all the image formats.
	// If you cant do this, you can redefine this list of supported libraries so images will be automatically converted into required format internally.
	// image/png is the only required format that must be supported and cannot be disabled.
	// Check supported formats here `https://tesseract-ocr.github.io/tessdoc/InputFormats.html`
	//
	// Default value is ["image/png", "image/jpeg", "image/tiff", "image/pnm", "image/gif", "image/webp"]. It atomatically supports image/file2llm-raw-bgra, whether you specify it or not.
	// Tesseract doesnt support compressed "image/bmp" image type. So its better to transcode it to PNG.
	SupportedImageFormats []string `json:"supportedImageFormats"`
}

Configuration for initializing Tesseract OCR provider

func DefaultTesseractConfig

func DefaultTesseractConfig() TesseractConfig

type TesseractModelType

type TesseractModelType string

Model type used by Tesseract

const TesseractModelBestQuality TesseractModelType = "BEST_QUALITY"

Model with best quality. Requires more processing power

const TesseractModelFast TesseractModelType = "FAST"

The fastest available model with low accuracy

const TesseractModelNormal TesseractModelType = "NORMAL"

Model that runs by default in tesseract instances

type TesseractPool added in v0.0.2

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

func NewTesseractPool added in v0.0.2

func NewTesseractPool(size uint32, workerConfig TesseractConfig) *TesseractPool

func (*TesseractPool) Destroy added in v0.0.2

func (p *TesseractPool) Destroy(ctx context.Context) error

func (*TesseractPool) Init added in v0.0.2

func (p *TesseractPool) Init(ctx context.Context) error

func (*TesseractPool) IsMimeTypeSupported added in v0.0.2

func (p *TesseractPool) IsMimeTypeSupported(mimeType string) bool

func (*TesseractPool) OCR added in v0.0.2

func (p *TesseractPool) OCR(ctx context.Context, image io.Reader) (string, error)

func (*TesseractPool) OCRWithProgress added in v0.0.10

func (p *TesseractPool) OCRWithProgress(ctx context.Context, image io.Reader) OCRProgress

type TesseractServer

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

Uses tesseract server as OCR backend. https://github.com/otiai10/ocrserver

func NewTesseractServer

func NewTesseractServer(config TesseractServerConfig) *TesseractServer

func (*TesseractServer) IsMimeTypeSupported

func (p *TesseractServer) IsMimeTypeSupported(mimeType string) bool

func (*TesseractServer) OCR

func (p *TesseractServer) OCR(ctx context.Context, image io.Reader) (string, error)

func (*TesseractServer) OCRWithProgress added in v0.0.10

func (p *TesseractServer) OCRWithProgress(ctx context.Context, image io.Reader) OCRProgress

type TesseractServerConfig

type TesseractServerConfig struct {
	// HTTP client used to make requests to the server
	Client *http.Client
	// Server base URL. For example http://127.0.0.1:8884
	BaseURL string
	// List of language codes that should be recognized. More languages - more processing time.
	// Order matters. Primary language has to go first as it will act as fallback. By default it will be ["eng"]
	// Make sure languages are installed on the server because default OCR server has only several languages enabled by default.
	Languages []string `json:"languages"`
}

func DefaultTesseractServerConfig added in v0.0.2

func DefaultTesseractServerConfig() TesseractServerConfig

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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