Documentation
¶
Overview ¶
Package ocr recognises text in images on the device: no network, no account. It's what a scanner needs for searchable PDFs, copying text off a page and searching inside documents.
res, err := ocr.Recognize(ctx, page, ocr.Options{})
fmt.Println(res.Text)
for _, l := range res.Lines {
for _, w := range l.Words {
pdf.InvisibleText(w.Text, w.Box) // a searchable layer
}
}
iOS and macOS use Apple's Vision framework; Android uses Google's ML Kit text recognition, bundled into the app (about 4 MB per CPU architecture), so it works offline and without Google Play services. ML Kit's bundled model reads Latin scripts; Vision also reads Chinese, Japanese, Korean, Cyrillic and more (see Options.Languages). Windows uses Windows.Media.Ocr, in the languages whose OCR packs are installed; Linux uses Tesseract, loaded at run time with the user's installed languages (the tesseract-ocr packages), Supported reporting whether it's there. Elsewhere Recognize returns giode.ErrNotSupported.
Android builds need the giode CLI, which adds ML Kit to the app from this package's android_dependencies.txt.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Line ¶
type Line struct {
Text string
// Box is the line's bounds in the image's pixels, top left origin.
Box image.Rectangle
// Confidence is from 0 to 1; 0 when the platform doesn't say.
Confidence float32
Words []Word
}
Line is a line of text.
type Options ¶
type Options struct {
// Languages are BCP 47 tags to read, most likely first: "en-US",
// "de-DE", "zh-Hans". Empty reads the platform's default (English,
// and other Latin-script languages). Vision only: ML Kit's bundled
// model reads Latin scripts whatever is asked.
Languages []string
// Fast trades accuracy for speed (Vision's fast level), for live
// recognition on camera frames.
Fast bool
}
Options configure recognition.