Api Reference

InitializeConfig

Referensi API publik untuk preset model, path model, dan tahapan inferensi tambahan.

InitializeConfig mengonfigurasi berkas model, kamus kosakata, dan jaringan inferensi tambahan untuk menginisialisasi sesi mesin OCR yang siap digunakan berulang kali.

Kontrak Arsitektur

Rendering diagram...

Skema Wire JSON Kanonikal

Untuk C FFI, JNI, dan serialisasi JSON pada binding independen:

{
  "template": "ppv6",
  "detection": {
    "modelPath": "models/det.rten",
    "thresh": 0.3,
    "boxThresh": 0.6,
    "unclipRatio": 2.0,
    "limitSideLen": 736,
    "limitType": "min",
    "useDilation": true
  },
  "recognition": {
    "modelPath": "models/rec.rten",
    "dictPath": "models/dict.txt"
  },
  "classification": {
    "enabled": true,
    "modelPath": "models/cls.rten",
    "thresh": 0.9
  },
  "orientation": {
    "enabled": true,
    "modelPath": "models/orient.rten",
    "thresh": 0.85
  }
}

Referensi Preset

PresetDefault Skala DetektorDefault Mode SkalaDefault Rasio UnclipArsitektur yang Kompatibel
ppv6 (Default)736min2.0PP-OCRv6 (Tiny, Small, Medium)
ppv5736min2.0PP-OCRv5 (Mobile, Server)
ppv4960max1.5PP-OCRv4 (Mobile, Server)
ppv3960max1.5PP-OCRv3

API Publik di Seluruh Binding

Pada Rust

use rusto::{InitializeConfig, RustO};

// Metode 1: Konstruktor dengan preset default PP-OCRv6
let config = InitializeConfig::ppv6("det.rten", "rec.rten", "dict.txt")
    .with_det_thresh(0.3)
    .with_det_box_thresh(0.6)
    .with_unclip_ratio(2.0)
    .with_use_dilation(true)
    .with_cls_threshold("cls.rten", 0.9)
    .with_orientation_threshold("orient.rten", 0.85);

let mut ocr = RustO::initialize(config)?;

// Metode 2: Mesin inferensi kustom via trait InferenceSession
// let ocr = RustO::with_custom_engines(config, custom_det_session, custom_rec_session)?;

Pada .NET / C#

using RustODotnet;

var config = new InitializeConfig
{
    Template = "ppv6",
    Detection = new DetectionConfig { ModelPath = "det.rten" },
    Recognition = new RecognitionConfig { ModelPath = "rec.rten", DictPath = "dict.txt" },
    Classification = new ClassificationConfig { Enabled = true, ModelPath = "cls.rten", Thresh = 0.9f },
    Orientation = new OrientationConfig { Enabled = true, ModelPath = "orient.rten", Thresh = 0.85f }
};

using var ocr = RustO.Initialize(config);

Pada iOS (Swift)

import RustO

let config = InitializeConfig(
    template: "ppv6",
    detection: DetectionConfig(modelPath: "det.rten"),
    recognition: RecognitionConfig(modelPath: "rec.rten", dictPath: "dict.txt"),
    classification: ClassificationConfig(enabled: true, modelPath: "cls.rten", thresh: 0.9),
    orientation: OrientationConfig(enabled: true, modelPath: "orient.rten", thresh: 0.85)
)

let ocr = try RustO.initialize(config: config)

Pada Android (Kotlin)

import com.byrizki.rusto.*

val config = InitializeConfig(
    template = "ppv6",
    detection = DetectionConfig(modelPath = "det.rten"),
    recognition = RecognitionConfig(modelPath = "rec.rten", dictPath: "dict.txt"),
    classification = ClassificationConfig(enabled = true, modelPath = "cls.rten", thresh = 0.9f),
    orientation = OrientationConfig(enabled = true, modelPath = "orient.rten", thresh = 0.85f)
)

val ocr = RustO.initialize(context, config)

Pada React Native

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

await initialize({
  preset: 'ppv6',
  models: {
    detection: 'det.rten',
    recognition: 'rec.rten',
    dictionary: 'dict.txt',
    classification: 'cls.rten',
    orientation: 'orient.rten',
  },
});

Pada C FFI

#include "rusto.h"

const char *config_json = "{\"template\":\"ppv6\",\"detection\":{\"modelPath\":\"det.rten\"},\"recognition\":{\"modelPath\":\"rec.rten\",\"dictPath\":\"dict.txt\"}}";
ROCRHandle *handle = rocr_initialize(config_json);

// Dealokasi saat selesai:
rocr_free(handle);