Api Reference

TextResult & Output Modes

Public reference for input sources, output shapes, bounding polygon coordinates, and text frames.

Every OCR detection execution processes one ImageSource and returns either structured bounding blocks or reconstructed spatial text.

📥 Input Image Sources

BindingFile / URI SourceIn-Memory Buffer SourceNotes
RustImageSource::Path(PathBuf)ImageSource::Bytes(Vec<u8>)In-memory decoding uses pure Rust image engine.
PythonImageSource.PATH(str)ImageSource.BYTES(bytes)Native UniFFI bindings.
Node.jsdetectTextFile(path)detectTextData(Buffer)Native N-API bindings.
JavadetectTextFile(path)detectTextData(byte[])JNA dynamic linking against librusto.
GolangDetectTextFile(path)DetectTextData([]byte)Native Cgo bindings against librusto.
Flutter/DartdetectTextFile(path)detectTextData(Uint8List)Pure Dart FFI & Flutter platform plugin.
.NETUriImageSource(string)BytesImageSource(byte[])Accepts filesystem paths or file: URIs.
Swift.uri(String).bytes(Data)Accepts filesystem paths or file URL strings.
KotlinImageSource.Uri(String)ImageSource.Bytes(ByteArray)Natively resolves content:// URIs and file:// paths.
React Native{ uri: string }{ base64: string } or { bytes: Uint8Array }Exactly one key required in object payload.

📐 Coordinate Space & Geometry

Coordinates are expressed in image pixel units relative to the top-left origin (0, 0):

Rendering diagram...
  • box_points: Exactly 4 quadrilateral polygon vertices: [Top-Left, Top-Right, Bottom-Right, Bottom-Left]. Follows true text rotation angle.
  • frame: Axis-aligned bounding rectangle: (left, top, width, height) computed from the polygon bounds.

📤 Output Modes Breakdown

ModeReturn ShapeUse Case
lines (Default)Structured List (TextResult[])Standard document reading, paragraph parsing, and form field extraction line by line.
wordsStructured List (TextResult[])Interactive word tapping, word-level highlighting, or granular bounding box overlays.
spatialPlaintext String (string)Preserves 2D columns, tabular alignment, receipt rows, and document indentations.

🗂️ Structured Data Model (TextResult)

[
  {
    "text": "Total Due",
    "score": 0.992,
    "box_points": [
      [40.0, 120.0],
      [140.0, 120.0],
      [140.0, 148.0],
      [40.0, 148.0]
    ],
    "frame": {
      "left": 40.0,
      "top": 120.0,
      "width": 100.0,
      "height": 28.0
    }
  },
  {
    "text": "$250.00",
    "score": 0.987,
    "box_points": [
      [280.0, 120.0],
      [360.0, 120.0],
      [360.0, 148.0],
      [280.0, 148.0]
    ],
    "frame": {
      "left": 280.0,
      "top": 120.0,
      "width": 80.0,
      "height": 28.0
    }
  }
]

Type Mapping Across Bindings

ConceptRust.NET / C#Swift (iOS)Kotlin (Android)React Native
CollectionVec<TextResult>IReadOnlyList<TextResult>[TextResult]List<TextResult>TextResult[]
Text Stringitem.textitem.Textitem.textitem.textitem.text
Confidenceitem.scoreitem.Scoreitem.scoreitem.scoreitem.score
Polygon Quaditem.box_pointsitem.BoxPointsitem.boxPointsitem.boxPointsitem.box_points
Frameitem.frameitem.Frameitem.frameitem.frameitem.frame

💻 Result Handling Examples

Rust

match ocr.detect_text(&source, &options)? {
    DetectTextResult::Structured(items) => {
        for item in items {
            println!("{} ({:.1}%) at [{}, {}]", item.text, item.score * 100.0, item.frame.left, item.frame.top);
        }
    }
    DetectTextResult::Spatial(spatial_text) => {
        println!("{spatial_text}");
    }
}

.NET / C#

var result = ocr.DetectText(source, options);

if (result is StructuredDetectTextResult structured)
{
    foreach (var item in structured.Items)
    {
        Console.WriteLine($"{item.Text} ({item.Score:P0}) [{item.Frame.Left}, {item.Frame.Top}]");
    }
}
else if (result is SpatialDetectTextResult spatial)
{
    Console.WriteLine(spatial.Text);
}

iOS (Swift)

let result = try ocr.detectText(source, options: options)

switch result {
case .structured(let items):
    for item in items {
        print("\(item.text) (\(item.score)) [\(item.frame.left), \(item.frame.top)]")
    }
case .spatial(let text):
    print(text)
}

Android (Kotlin)

when (val result = ocr.detectText(source, options)) {
    is DetectTextResult.Structured -> {
        result.items.forEach { item ->
            println("${item.text} (${item.score}) [${item.frame.left}, ${item.frame.top}]")
        }
    }
    is DetectTextResult.Spatial -> {
        println(result.text)
    }
}

React Native

// Lines output -> TextResult[]
const lines = await detectText({ uri }, { output: 'lines' });
lines.forEach((item) => console.log(item.text, item.frame));

// Spatial output -> string
const spatialText = await detectText({ uri }, { output: 'spatial' });
console.log(spatialText);