hocr

package
v0.15.0 Latest Latest
Warning

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

Go to latest
Published: Nov 21, 2025 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CleanProviderResponse

func CleanProviderResponse(content string) string

CleanProviderResponse cleans up provider response for XML compatibility

func ConvertToBasicHOCR

func ConvertToBasicHOCR(response OCRResponse) string

ConvertToBasicHOCR converts an OCR response to basic hOCR without LLM transcription

func CreateTextImage

func CreateTextImage(text, tempDir, filename string) (string, error)

CreateTextImage creates an image containing the specified text

func ExtractWordImage

func ExtractWordImage(imagePath string, bbox BoundingPoly, tempDir string, wordIndex int) (string, error)

ExtractWordImage extracts a word region from the source image

func TranscribeWordsIndividually

func TranscribeWordsIndividually(imagePath string, response OCRResponse, provider providers.Provider, config providers.Config) (string, error)

TranscribeWordsIndividually extracts individual word images and transcribes each one

func WrapInHOCRDocument

func WrapInHOCRDocument(content string) string

WrapInHOCRDocument wraps content in a complete hOCR HTML document

Types

type Block

type Block struct {
	BoundingBox BoundingPoly `json:"boundingBox"`
	Paragraphs  []Paragraph  `json:"paragraphs"`
	BlockType   string       `json:"blockType"`
}

type BoundingPoly

type BoundingPoly struct {
	Vertices []Vertex `json:"vertices"`
}

type FullTextAnnotation

type FullTextAnnotation struct {
	Pages []Page `json:"pages"`
	Text  string `json:"text"`
}

type LineBox

type LineBox struct {
	Words               []WordBox
	X, Y, Width, Height int
}

LineBox represents a line of text containing multiple words

type OCRResponse

type OCRResponse struct {
	Responses []Response `json:"responses"`
}

OCRResponse and related types for word detection

func DetectWordBoundariesCustom

func DetectWordBoundariesCustom(imagePath string) (OCRResponse, error)

DetectWordBoundariesCustom uses custom image processing algorithm to find word boundaries

type Page

type Page struct {
	Width  int     `json:"width"`
	Height int     `json:"height"`
	Blocks []Block `json:"blocks"`
}

type Paragraph

type Paragraph struct {
	BoundingBox BoundingPoly `json:"boundingBox"`
	Words       []Word       `json:"words"`
}

type Response

type Response struct {
	FullTextAnnotation *FullTextAnnotation `json:"fullTextAnnotation"`
}

type Symbol

type Symbol struct {
	BoundingBox BoundingPoly `json:"boundingBox"`
	Text        string       `json:"text"`
}

type Vertex

type Vertex struct {
	X int `json:"x"`
	Y int `json:"y"`
}

type Word

type Word struct {
	BoundingBox BoundingPoly `json:"boundingBox"`
	Symbols     []Symbol     `json:"symbols"`
}

type WordBox

type WordBox struct {
	X, Y, Width, Height int
	Text                string
}

WordBox represents a detected word with its bounding box

type WordImage

type WordImage struct {
	Index       int
	BoundingBox BoundingPoly
	ImagePath   string
	Text        string // Will be filled by transcription
}

WordImage represents an extracted word with its image data and metadata

Jump to

Keyboard shortcuts

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