Kreuzberg.OcrBoundingGeometry (kreuzberg v4.4.2)

Copy Markdown View Source

Bounding geometry for OCR-extracted text elements.

Represents the geometric positioning of OCR-detected text, supporting both rectangular (left/top/width/height) and point-based (polygon points) geometry definitions.

Fields

  • :type - Geometry type ("rect" or "polygon")
  • :left - Left x-coordinate for rectangular geometry, or nil
  • :top - Top y-coordinate for rectangular geometry, or nil
  • :width - Width for rectangular geometry, or nil
  • :height - Height for rectangular geometry, or nil
  • :points - Array of [x, y] points for polygon geometry, or nil

Examples

iex> geometry = %Kreuzberg.OcrBoundingGeometry{
...>   type: "rect",
...>   left: 10.0,
...>   top: 20.0,
...>   width: 100.0,
...>   height: 50.0
...> }
iex> geometry.type
"rect"

Summary

Functions

Creates an OcrBoundingGeometry struct from a map.

Converts an OcrBoundingGeometry struct to a map.

Types

t()

@type t() :: %Kreuzberg.OcrBoundingGeometry{
  height: float() | nil,
  left: float() | nil,
  points: [[float()]] | nil,
  top: float() | nil,
  type: String.t(),
  width: float() | nil
}

Functions

from_map(data)

@spec from_map(map()) :: t()

Creates an OcrBoundingGeometry struct from a map.

Parameters

  • data - A map containing geometry fields

Returns

An OcrBoundingGeometry struct with properly typed fields.

Examples

iex> geometry_map = %{
...>   "type" => "rect",
...>   "left" => 10.0,
...>   "top" => 20.0,
...>   "width" => 100.0,
...>   "height" => 50.0
...> }
iex> geometry = Kreuzberg.OcrBoundingGeometry.from_map(geometry_map)
iex> geometry.type
"rect"

to_map(geometry)

@spec to_map(t()) :: map()

Converts an OcrBoundingGeometry struct to a map.

Parameters

  • geometry - An OcrBoundingGeometry struct

Returns

A map with string keys representing all fields.

Examples

iex> geometry = %Kreuzberg.OcrBoundingGeometry{
...>   type: "rect",
...>   left: 10.0,
...>   top: 20.0,
...>   width: 100.0,
...>   height: 50.0
...> }
iex> Kreuzberg.OcrBoundingGeometry.to_map(geometry)
%{
  "type" => "rect",
  "left" => 10.0,
  ...
}