Api Reference

TextResult & Mode Keluaran

Referensi sumber masukan, format keluaran, koordinat poligon batas, dan frame teks.

Setiap eksekusi deteksi OCR memproses satu ImageSource dan menghasilkan blok pembatas terstruktur atau teks tata letak spasial yang direkonstruksi.

πŸ“₯ Sumber Gambar Masukan

BindingSumber Berkas / URISumber Buffer Memori RAMCatatan
RustImageSource::Path(PathBuf)ImageSource::Bytes(Vec<u8>)Dekode byte memori menggunakan mesin image Rust murni.
PythonImageSource.PATH(str)ImageSource.BYTES(bytes)Binding native UniFFI.
Node.jsdetectTextFile(path)detectTextData(Buffer)Binding native N-API.
JavadetectTextFile(path)detectTextData(byte[])Dynamic linking JNA ke librusto.
GolangDetectTextFile(path)DetectTextData([]byte)Binding Cgo native ke librusto.
Flutter/DartdetectTextFile(path)detectTextData(Uint8List)Pure Dart FFI & plugin platform Flutter.
.NETUriImageSource(string)BytesImageSource(byte[])Menerima path berkas sistem atau URI file:.
Swift.uri(String).bytes(Data)Menerima path berkas atau string URL berkas.
KotlinImageSource.Uri(String)ImageSource.Bytes(ByteArray)Mengurai URI content:// Android dan file:// secara otomatis.
React Native{ uri: string }{ base64: string } atau { bytes: Uint8Array }Wajib memuat tepat satu properti dalam objek masukan.

πŸ“ Ruang Koordinat & Geometri

Koordinat dinyatakan dalam satuan piksel gambar terhadap titik asal kiri-atas (0, 0):

Rendering diagram...
  • box_points: Tepat 4 titik sudut poligon segiempat: [Kiri-Atas, Kanan-Atas, Kanan-Bawah, Kiri-Bawah]. Mengikuti sudut kemiringan teks yang sebenarnya.
  • frame: Kotak batas sejajar sumbu (axis-aligned bounding rectangle): (left, top, width, height) yang dihitung dari batas terluar poligon.

πŸ“€ Rincian Mode Keluaran

ModeBentuk Hasil KembalianKegunaan
lines (Default)Daftar Terstruktur (TextResult[])Membaca dokumen standar, paragraf teks, dan formulir baris per baris.
wordsDaftar Terstruktur (TextResult[])Interaksi klik per kata, penyorotan teks kata per kata, atau visualisasi kotak batas granular.
spatialString Teks Biasa (string)Mempertahankan kolom 2D, perataan tabel, baris struk, dan indentasi dokumen.

πŸ—‚οΈ Model Data Terstruktur (TextResult)

[
  {
    "text": "Total Tagihan",
    "score": 0.992,
    "box_points": [
      [40.0, 120.0],
      [160.0, 120.0],
      [160.0, 148.0],
      [40.0, 148.0]
    ],
    "frame": {
      "left": 40.0,
      "top": 120.0,
      "width": 120.0,
      "height": 28.0
    }
  },
  {
    "text": "Rp2.500.000",
    "score": 0.987,
    "box_points": [
      [280.0, 120.0],
      [380.0, 120.0],
      [380.0, 148.0],
      [280.0, 148.0]
    ],
    "frame": {
      "left": 280.0,
      "top": 120.0,
      "width": 100.0,
      "height": 28.0
    }
  }
]

Pemetaan Tipe Properti Lintas Bahasa

KonsepRust.NET / C#Swift (iOS)Kotlin (Android)React Native
Koleksi ListVec<TextResult>IReadOnlyList<TextResult>[TextResult]List<TextResult>TextResult[]
Teks Stringitem.textitem.Textitem.textitem.textitem.text
Kepercayaanitem.scoreitem.Scoreitem.scoreitem.scoreitem.score
Poligon Quaditem.box_pointsitem.BoxPointsitem.boxPointsitem.boxPointsitem.box_points
Frame Kotakitem.frameitem.Frameitem.frameitem.frameitem.frame

πŸ’» Contoh Penanganan Hasil di Berbagai Bahasa

Pada Rust

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

Pada .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);
}

Pada 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)
}

Pada 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)
    }
}

Pada React Native

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

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