OCR
package goodmem // import "fury.io/pairsys/goodmem"Document OCR — text extraction from PDFs / images.
Methods are called as client.OCR().<Method>(ctx, ...) on a *goodmem.Client. Service: OCRService.
Index
- type OCRService
- type OcrDocumentRequest
- type OcrInputFormat
- type OcrDocumentResponse
- type OcrPageResult
- type DocumentTimings
- type OcrPage
- type RpcStatus
- type OcrLayout
- type PageTimings
- type ImageInfo
- type OcrCell
- type BoundingBox
- type OcrCategory
type OCRService
type OCRService struct{ … }
Access this service as client.OCR() on a *goodmem.Client. Its methods follow.
func (s *OCRService) Document
func (s *OCRService) Document(ctx context.Context, req *models.OCRDocumentRequest) (*models.OCRDocumentResponse, error)
Run OCR on a document or image. Pass base64-encoded document bytes as content. The server auto-detects format; set format explicitly only if needed.
HTTP — POST /v1/ocr:document
Parameters
ctx(context.Context) — carries the deadline and cancellation signal for the call.req(*models.OCRDocumentRequest) — the request payload. The linked type documents every field and its JSON wire name.
Returns — (*models.OCRDocumentResponse, error)
Example
imageB64 := base64.StdEncoding.EncodeToString([]byte("not-a-real-image"))
result, err := client.OCR().Document(ctx, &models.OCRDocumentRequest{
Content: goodmem.Ptr(imageB64),
Format: goodmem.Ptr(models.OCRInputFormatPNG),
IncludeMarkdown: goodmem.Ptr(true),
})
if err == nil {
_ = result.PageCount
}func (s *OCRService) DocumentFromFile
func (s *OCRService) DocumentFromFile(ctx context.Context, filePath string, req *models.OCRDocumentRequest) (*models.OCRDocumentResponse, error)
Run OCR on a document or image. Pass base64-encoded document bytes as content. The server auto-detects format; set format explicitly only if needed.
Convenience variant: reads filePath from disk, base64-encodes the bytes, infers the content type from the file extension, and POSTs a JSON request.
HTTP — POST /v1/ocr:document
Parameters
ctx(context.Context) — carries the deadline and cancellation signal for the call.filePath(string) — path to a local file. It is read into memory, base64-encoded, and the content type is inferred from the extension.req(*models.OCRDocumentRequest) — the request payload. The linked type documents every field and its JSON wire name.
Returns — (*models.OCRDocumentResponse, error)
Example
resp, err := client.OCR().DocumentFromFile(ctx, "/tmp/file.bin", &models.OCRDocumentRequest{ /* required fields */ })
if err != nil {
log.Fatal(err)
}
_ = resptype OcrDocumentRequest
type OcrDocumentRequest struct{ … }
Request body for OCR document processing.
Content(string, wirecontent) — Base64-encoded document bytesFormat(models.OcrInputFormat, optional, wireformat) — Input format hint (AUTO, PDF, TIFF, PNG, JPEG, BMP)IncludeRawJSON(bool, optional, wireincludeRawJson) — Include raw OCR JSON payload in the responseIncludeMarkdown(bool, optional, wireincludeMarkdown) — Include markdown rendering in the responseStartPage(int32, optional, wirestartPage) — 0-based inclusive start pageEndPage(int32, optional, wireendPage) — 0-based inclusive end page
type OcrInputFormat
type OcrInputFormat string
OCR input format hint.
String enum (type OcrInputFormat string): "AUTO" · "PDF" · "TIFF" · "PNG" · "JPEG" · "BMP"
type OcrDocumentResponse
type OcrDocumentResponse struct{ … }
Response containing page-ordered OCR results.
DetectedFormat(models.OcrInputFormat, wiredetectedFormat) — Detected input formatPageCount(int32, wirepageCount) — Number of pages processed after applying the rangePages([]models.OcrPageResult, wirepages) — Ordered per-page OCR resultsTimings(models.DocumentTimings, wiretimings) — Aggregate timing statistics
type OcrPageResult
type OcrPageResult struct{ … }
Per-page OCR result containing output or error status.
PageIndex(int32, wirepageIndex) — 0-based page indexPage(models.OcrPage, optional, wirepage) — OCR output for the pageStatus(models.RpcStatus, optional, wirestatus) — Error status for the page
type DocumentTimings
type DocumentTimings struct{ … }
Aggregate timing statistics for an OCR request.
WallTimeMs(int64, wirewallTimeMs) — End-to-end request time (ms)SumQueueWaitMs(int64, wiresumQueueWaitMs) — Sum of per-page queue wait times (ms)SumRenderMs(int64, wiresumRenderMs) — Sum of per-page render times (ms)SumOCRMs(int64, wiresumOcrMs) — Sum of per-page OCR times (ms)SumPageTotalMs(int64, wiresumPageTotalMs) — Sum of per-page total times (ms)
type OcrPage
type OcrPage struct{ … }
OCR output for a single page.
RawJSON(string, optional, wirerawJson) — Raw OCR JSON payload when requestedMarkdown(string, optional, wiremarkdown) — Markdown rendering when requestedLayout(models.OcrLayout, wirelayout) — Parsed layout outputTimings(models.PageTimings, wiretimings) — Timing breakdown for the pageImage(models.ImageInfo, wireimage) — Rendered image metadata
type RpcStatus
type RpcStatus struct{ … }
Status payload for per-page OCR errors.
Code(int32, wirecode) — gRPC status code as defined by google.rpc.CodeMessage(string, optional, wiremessage) — Human-readable error message
type OcrLayout
type OcrLayout struct{ … }
Parsed OCR layout output for a page.
Cells([]models.OcrCell, wirecells) — Layout cells in reading order
type PageTimings
type PageTimings struct{ … }
Per-page timing breakdown for OCR processing.
QueueWaitMs(int64, wirequeueWaitMs) — Time spent waiting in the render queue (ms)RenderMs(int64, wirerenderMs) — Time spent rendering the page image (ms)OCRMs(int64, wireocrMs) — Time spent running OCR (ms)TotalMs(int64, wiretotalMs) — Total page processing time (ms)
type ImageInfo
type ImageInfo struct{ … }
Rendered image metadata for an OCR page.
WidthPx(int32, wirewidthPx) — Rendered image width in pixelsHeightPx(int32, wireheightPx) — Rendered image height in pixelsDpi(int32, wiredpi) — Rendering DPI
type OcrCell
type OcrCell struct{ … }
Single OCR layout element.
Bbox(models.BoundingBox, optional, wirebbox) — Bounding box in page coordinatesCategoryLabel(string, wirecategoryLabel) — Raw category label emitted by OCRCategory(models.OcrCategory, wirecategory) — Normalized OCR categoryText(string, wiretext) — OCR text content
type BoundingBox
type BoundingBox struct{ … }
Bounding box coordinates in page space.
X1(float64, wirex1) — Left coordinateY1(float64, wirey1) — Top coordinateX2(float64, wirex2) — Right coordinateY2(float64, wirey2) — Bottom coordinate
type OcrCategory
type OcrCategory string
Normalized OCR layout category.
String enum (type OcrCategory string): "UNSPECIFIED" · "CAPTION" · "FOOTNOTE" · "FORMULA" · "LIST_ITEM" · "PAGE_FOOTER" · "PAGE_HEADER" · "PICTURE" · "SECTION_HEADER" · "TABLE" · "TEXT" · "TITLE" · "OTHER" · "UNKNOWN"