Api Reference

OcrRunOptions

Request-local output options, resize bounds, DBNet detector settings, and postprocessing reference.

OcrRunOptions (DetectTextOptions in React Native) configures runtime parameters for an individual OCR execution. It applies to a single detectText call without mutating or re-allocating the underlying engine session.

Rendering diagram...

Canonical Wire Schema

{
  "output": "lines",
  "lineYThreshold": 0.5,
  "wordXThreshold": 0.4,
  "textScore": 0.5,
  "classification": false,
  "orientation": false,
  "minHeight": 32,
  "maxSideLen": 1600,
  "minSideLen": 64,
  "widthHeightRatio": -1,
  "detection": {
    "limitSideLen": 960,
    "limitType": "max",
    "mean": [0.485, 0.456, 0.406],
    "std": [0.229, 0.224, 0.225]
  },
  "postprocess": {
    "threshold": 0.3,
    "boxThreshold": 0.6,
    "maxCandidates": 1000,
    "unclipRatio": 2.0,
    "useDilation": true
  }
}

Parameters Specification

1. Output & Grouping Controls

OptionTypeDefaultAllowed RangeDescription
outputstring / enumlineslines, words, spatialSelects structured lines, structured words, or formatted spatial text.
lineYThresholdfloat0.5>= 0.0Vertical tolerance multiplier for clustering bounding boxes into lines.
wordXThresholdfloat0.4>= 0.0Horizontal character-width multiplier for column separation and word spacing.
textScorefloatEngine Preset (0.5)0.0 .. 1.0Minimum recognition confidence cutoff score.
classificationbooleanfalsetrue, falseEvaluates 180° text line orientation classifier (requires CLS model).
orientationbooleanfalsetrue, falseEvaluates whole-page orientation classifier (requires Orient model).

2. Image Scaling & Bounds

OptionTypeDefaultAllowed RangeDescription
minSideLenfloat64.0> 0.0Minimum allowed side length for bounded scaling.
maxSideLenfloat1600.0minSideLen <= maxSideLenMaximum image side length (prevents out-of-memory on 48MP photos).
minHeightfloat32.0> 0.0Minimum vertical height for morphological padding.
widthHeightRatiofloat-1.0> 0.0 or -1.0Recognition padding aspect ratio. -1 preserves native image aspect ratio.

3. Detector Input Tuning (detection)

OptionTypeDefaultAllowed RangeDescription
limitSideLenintegerPreset (736 / 960)1 .. 32767Target image resize bound for DBNet detector input.
limitTypestringPreset (min / max)min, maxmin: scales shorter side to target. max: caps longer side at target.
meanfloat[3][0.485, 0.456, 0.406]3 finite numbersChannel-wise RGB normalization mean.
stdfloat[3][0.229, 0.224, 0.225]3 non-zero numbersChannel-wise RGB normalization standard deviation.

4. Detector Postprocessing (postprocess)

OptionTypeDefaultAllowed RangeDescription
thresholdfloatPreset (0.3)0.0 .. 1.0Pixel binarization probability map cutoff threshold.
boxThresholdfloatPreset (0.6 / 0.5)0.0 .. 1.0Text candidate polygon average confidence score threshold.
maxCandidatesinteger1000>= 1Maximum candidate polygon contours retained for processing.
unclipRatiofloatPreset (2.0 / 1.5)> 0.0Vatti polygon expansion ratio to capture full stroke ascenders/descenders.
useDilationbooleanPreset (true / false)true, falseApplies 2×2 morphological dilation for faint or broken strokes.

Complete Multi-Language Examples

Rust

use rusto::{DetectionRunOptions, OcrRunOptions, OutputGranularity, PostprocessRunOptions};

let options = OcrRunOptions {
    output: OutputGranularity::Words,
    text_score: Some(0.55),
    line_y_threshold: Some(0.5),
    word_x_threshold: Some(0.4),
    max_side_len: Some(1600.0),
    detection: Some(DetectionRunOptions {
        limit_side_len: Some(960),
        limit_type: Some("max".into()),
        ..Default::default()
    }),
    postprocess: Some(PostprocessRunOptions {
        use_dilation: Some(true),
        unclip_ratio: Some(2.0),
        ..Default::default()
    }),
    ..Default::default()
};

.NET / C#

using RustODotnet;

var options = new OcrRunOptions
{
    Output = OutputGranularity.Words,
    TextScore = 0.55f,
    LineYThreshold = 0.5f,
    WordXThreshold = 0.4f,
    MaxSideLen = 1600f,
    Detection = new DetectionRunOptions
    {
        LimitSideLen = 960,
        LimitType = "max"
    },
    Postprocess = new PostprocessRunOptions
    {
        UseDilation = true,
        UnclipRatio = 2.0f
    }
};

Swift (iOS)

import RustO

let options = OcrRunOptions(
    output: .words,
    lineYThreshold: 0.5,
    wordXThreshold: 0.4,
    textScore: 0.55,
    maxSideLen: 1600,
    detection: DetectionRunOptions(limitSideLen: 960, limitType: "max"),
    postprocess: PostprocessRunOptions(useDilation: true, unclipRatio: 2.0)
)

Kotlin (Android)

import com.byrizki.rusto.*

val options = OcrRunOptions(
    output = OutputGranularity.WORDS,
    lineYThreshold = 0.5f,
    wordXThreshold = 0.4f,
    textScore = 0.55f,
    maxSideLen = 1600f,
    detection = DetectionRunOptions(limitSideLen = 960, limitType = "max"),
    postprocess = PostprocessRunOptions(useDilation = true, unclipRatio = 2.0f)
)

React Native

import { DetectTextOptions } from '@rustors/react-native';

const options: DetectTextOptions = {
  output: 'words',
  lineYThreshold: 0.5,
  wordXThreshold: 0.4,
  textScore: 0.55,
  maxSideLen: 1600,
  detection: {
    limitSideLen: 960,
    limitType: 'max',
  },
  postprocess: {
    useDilation: true,
    unclipRatio: 2.0,
  },
};