ocr

package
v1.6.3 Latest Latest
Warning

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

Go to latest
Published: Feb 3, 2026 License: MIT Imports: 1 Imported by: 0

Documentation

Overview

Package ocr provides OCR (Optical Character Recognition) capabilities for extracting text from images in scanned PDFs.

This is the stub implementation used when the "ocr" build tag is not set. All functions return ErrOCRNotEnabled.

To enable OCR, rebuild with the "ocr" build tag:

go build -tags ocr

This requires Tesseract to be installed. On macOS:

brew install tesseract

On Ubuntu/Debian:

apt-get install tesseract-ocr

Index

Constants

This section is empty.

Variables

View Source
var ErrOCRNotEnabled = errors.New("OCR support not enabled; rebuild with -tags ocr")

ErrOCRNotEnabled is returned when OCR functions are called but OCR support was not compiled in. Rebuild with -tags ocr to enable OCR support.

Functions

This section is empty.

Types

type Client

type Client struct{}

Client is a stub OCR client that returns errors for all operations.

func New

func New() (*Client, error)

New returns an error indicating OCR support is not enabled. To enable OCR, rebuild with: go build -tags ocr

func (*Client) Close

func (c *Client) Close() error

Close is a no-op for the stub client. It is safe to call on a nil client.

func (*Client) RecognizeImage

func (c *Client) RecognizeImage(imageData []byte) (string, error)

RecognizeImage returns an error indicating OCR support is not enabled.

func (*Client) SetLanguage

func (c *Client) SetLanguage(lang string) error

SetLanguage returns an error indicating OCR support is not enabled.

func (*Client) SetPageSegMode

func (c *Client) SetPageSegMode(mode PageSegMode) error

SetPageSegMode returns an error indicating OCR support is not enabled.

type PageSegMode added in v1.6.1

type PageSegMode int

PageSegMode represents page segmentation modes for OCR. These control how Tesseract analyzes the page layout.

const (
	PSM_OSD_ONLY               PageSegMode = 0  // Orientation and script detection only
	PSM_AUTO_OSD               PageSegMode = 1  // Automatic with OSD
	PSM_AUTO_ONLY              PageSegMode = 2  // Automatic, no OSD or OCR
	PSM_AUTO                   PageSegMode = 3  // Fully automatic (default)
	PSM_SINGLE_COLUMN          PageSegMode = 4  // Single column of variable sizes
	PSM_SINGLE_BLOCK_VERT_TEXT PageSegMode = 5  // Single uniform block of vertically aligned text
	PSM_SINGLE_BLOCK           PageSegMode = 6  // Single uniform block of text
	PSM_SINGLE_LINE            PageSegMode = 7  // Single text line
	PSM_SINGLE_WORD            PageSegMode = 8  // Single word
	PSM_CIRCLE_WORD            PageSegMode = 9  // Single word in a circle
	PSM_SINGLE_CHAR            PageSegMode = 10 // Single character
	PSM_SPARSE_TEXT            PageSegMode = 11 // Find as much text as possible
	PSM_SPARSE_TEXT_OSD        PageSegMode = 12 // Sparse text with OSD
	PSM_RAW_LINE               PageSegMode = 13 // Treat image as single text line
)

Page segmentation modes (matching the OCR-enabled implementation).

Jump to

Keyboard shortcuts

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