sikuli-go provides OCR APIs in Finder and Region:
Finder.ReadText(params OCRParams)Finder.FindText(query, params OCRParams)Region.ReadText(source, params OCRParams)Region.FindText(source, query, params OCRParams)By default, OCR is disabled at build time and these APIs return ErrBackendUnsupported.
sikuli-go includes an optional OCR backend adapter for:
github.com/otiai10/gosseract/v2go.modNative runtime requirements:
eng)Build or test with OCR enabled:
go test -tags gosseract ./...
go build -tags gosseract ./...
Install native dependencies:
brew install leptonica tesseract pkg-config
Export build/link flags (Apple Silicon/Homebrew):
export HOMEBREW_PREFIX="$(brew --prefix)"
export PKG_CONFIG_PATH="$HOMEBREW_PREFIX/lib/pkgconfig:$PKG_CONFIG_PATH"
export CGO_CFLAGS="-I$HOMEBREW_PREFIX/include"
export CGO_CPPFLAGS="-I$HOMEBREW_PREFIX/include"
export CGO_LDFLAGS="-L$HOMEBREW_PREFIX/lib -llept -ltesseract"
Validate package config and run tests:
pkg-config --cflags lept tesseract
pkg-config --libs lept tesseract
go clean -cache -testcache
go test -tags gosseract ./internal/ocr ./pkg/sikuli
If you see ld: library 'lept' not found, create compatibility symlinks:
sudo ln -sf "$(brew --prefix leptonica)/lib/libleptonica.dylib" /opt/homebrew/lib/liblept.dylib
sudo ln -sf "$(brew --prefix leptonica)/lib/libleptonica.dylib" /usr/local/lib/liblept.dylib
fatal error: 'leptonica/allheaders.h' file not foundThis means the compiler cannot find Leptonica headers while building the gosseract CGO path.
brew install leptonica tesseract pkg-config
allheaders.h is located:find /opt/homebrew /usr/local -name "allheaders.h" 2>/dev/null
pkg-config + Homebrew prefix exports (portable across Intel/Apple Silicon):export HOMEBREW_PREFIX="$(brew --prefix)"
export PKG_CONFIG_PATH="$HOMEBREW_PREFIX/lib/pkgconfig:$PKG_CONFIG_PATH"
export CGO_CFLAGS="-I$HOMEBREW_PREFIX/include"
export CGO_CPPFLAGS="-I$HOMEBREW_PREFIX/include"
export CGO_CXXFLAGS="-I$HOMEBREW_PREFIX/include"
export CGO_LDFLAGS="-L$HOMEBREW_PREFIX/lib -llept -ltesseract"
export LEPT_PREFIX="$(brew --prefix leptonica)"
export TESS_PREFIX="$(brew --prefix tesseract)"
export CGO_CFLAGS="-I$LEPT_PREFIX/include -I$TESS_PREFIX/include"
export CGO_CPPFLAGS="-I$LEPT_PREFIX/include -I$TESS_PREFIX/include"
export CGO_CXXFLAGS="-I$LEPT_PREFIX/include -I$TESS_PREFIX/include"
export CGO_LDFLAGS="-L$LEPT_PREFIX/lib -L$TESS_PREFIX/lib -llept -ltesseract"
pkg-config --cflags lept tesseract
pkg-config --libs lept tesseract
go clean -cache -testcache
go test -tags gosseract ./internal/ocr ./pkg/sikuli
OCRParams supports:
Language (default: "eng")TrainingDataPath (optional tessdata path)MinConfidence (clamped to [0,1])Timeout (negative values become 0)CaseSensitive (for FindText)txt, err := finder.ReadText(sikuli.OCRParams{
Language: "eng",
})
matches, err := finder.FindText("Submit", sikuli.OCRParams{
MinConfidence: 0.6,
})