Documentation
¶
Overview ¶
Package ocr is a Go SDK for running OCR via VLM models (PaddleOCR-VL, Qwen2.5-VL, etc.) through LM Studio or any OpenAI-compatible API.
Usage:
doc, err := ocr.New(paddleocrvl.New()).
LMStudio("http://127.0.0.1:1234/v1").
ParseImage(ctx, "demo.png")
md, _ := ocr.Markdown(doc)
Index ¶
- Variables
- func HTML(doc *document.Document, imageSrc string) (string, error)
- func JSON(doc *document.Document) (string, error)
- func Markdown(doc *document.Document) (string, error)
- func RecordFail(imagePath string)
- func Text(doc *document.Document) (string, error)
- type Client
- func (c *Client) Debug(path string) *Client
- func (c *Client) LMStudio(url string) *Client
- func (c *Client) MaxHeight(h int) *Client
- func (c *Client) MaxRetries(n int) *Client
- func (c *Client) Model(name string) *Client
- func (c *Client) OnProgress(fn ProgressFunc) *Client
- func (c *Client) Overlap(px int) *Client
- func (c *Client) Page(n int) *Client
- func (c *Client) ParseImage(ctx context.Context, imagePath string) (*document.Document, error)
- func (c *Client) ParseImageReader(ctx context.Context, r io.Reader, imagePath string) (*document.Document, error)
- func (c *Client) SaveSlices(v bool) *Client
- func (c *Client) SystemPrompt(prompt string) *Client
- type ProgressFunc
Constants ¶
This section is empty.
Variables ¶
var ErrSkipped = errors.New("skipped")
Functions ¶
func HTML ¶
HTML renders the document as positioned HTML. imageSrc is used as the src attribute of the background <img> tag.
func RecordFail ¶
func RecordFail(imagePath string)
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
func New ¶
New creates a new Client with the given provider. The provider supplies the default model name, system prompt, and decoder.
func (*Client) Debug ¶
Debug enables debug mode: raw model output is saved to path (JSON array). If path already exists, the model is skipped and cached raw output is replayed.
func (*Client) MaxHeight ¶
MaxHeight sets the maximum image height before slicing. 0 (default) means no slicing. Overlap between slices is 200px by default.
func (*Client) MaxRetries ¶
MaxRetries sets the max retries when the model output has no LOC tokens. Default is 3.
func (*Client) OnProgress ¶
func (c *Client) OnProgress(fn ProgressFunc) *Client
OnProgress sets a callback invoked for each slice during slicing.
func (*Client) ParseImage ¶
ParseImage runs OCR on an image file and returns a structured Document. If MaxHeight is set and the image exceeds it, the image is split into overlapping horizontal slices, each processed separately, then merged.
func (*Client) ParseImageReader ¶
func (c *Client) ParseImageReader(ctx context.Context, r io.Reader, imagePath string) (*document.Document, error)
ParseImageReader runs OCR on an image from an io.Reader.
func (*Client) SaveSlices ¶
SaveSlices enables saving slice JPEGs and per-slice raw.json/html to disk.
func (*Client) SystemPrompt ¶
SystemPrompt overrides the default system prompt.
type ProgressFunc ¶
Client is the convenient top-level API for OCR. ProgressFunc is called with the current slice index and total during slicing.
Directories
¶
| Path | Synopsis |
|---|---|
|
cmd
|
|
|
ocr
command
|
|
|
paddle2html
command
Command paddle2html converts PaddleOCR JSON output to an HTML overlay using the project's own document types and output.HTML renderer.
|
Command paddle2html converts PaddleOCR JSON output to an HTML overlay using the project's own document types and output.HTML renderer. |
|
Package imageutil provides image processing utilities for OCR.
|
Package imageutil provides image processing utilities for OCR. |
|
Package provider defines the interface for OCR model providers.
|
Package provider defines the interface for OCR model providers. |
|
paddleocrpy
Package paddleocrpy provides OCR via the local PaddleOCR Python library.
|
Package paddleocrpy provides OCR via the local PaddleOCR Python library. |
|
paddleocrvl
Package paddleocrvl implements the provider.Provider interface for PaddleOCR-VL models, which output text with <|LOC_xxx|> location tokens.
|
Package paddleocrvl implements the provider.Provider interface for PaddleOCR-VL models, which output text with <|LOC_xxx|> location tokens. |