Advance Guide
Classification & Orientation
How to configure text line orientation classifiers (CLS) and full-page document angle rotators.
Mobile camera captures and document scans often feature skewed angles, upside-down documents, or mixed text directions.
RustO! provides two distinct orientation correction stages:
Rendering diagram...
1. Text Line Direction Classifier (CLS)
The CLS model inspects cropped text regions produced by the DBNet detector. If a text line is inverted (180° upside-down), it rotates the crop upright before passing it to the CTC text recognizer.
!NOTE Text line direction classification (
cls.rten) is supported on PP-OCRv4 and PP-OCRv5 models. PP-OCRv6 models use an orientation-robust recognition network.
Initialization Configuration
use rusto::InitializeConfig;
// Initialize engine and attach CLS model with 0.9 confidence threshold
let config = InitializeConfig::ppv5("models/det.rten", "models/rec.rten", "models/dict.txt")
.with_cls_threshold("models/cls.rten", 0.9);
let mut ocr = RustO::initialize(config)?;
Request-Local Activation
Enable CLS classification for specific scans via OcrRunOptions:
let options = OcrRunOptions {
classification: Some(true), // Activates CLS evaluation for this request
..Default::default()
};
2. Whole-Page Document Orientation Classifier
For documents photographed sideways (90° / 270°) or completely upside down (180°):
let config = InitializeConfig::ppv5("models/det.rten", "models/rec.rten", "models/dict.txt")
.with_orientation_threshold("models/orient.rten", 0.85);
let mut ocr = RustO::initialize(config)?;
Request-Local Activation
let options = OcrRunOptions {
orientation: Some(true), // Classifies and rotates the whole page before detection
..Default::default()
};
📱 Cross-Binding Example (React Native)
import { detectText, initialize } from '@rustors/react-native';
// Initialize with model references
await initialize({
preset: 'ppv5',
models: {
detection: 'det.rten',
recognition: 'rec.rten',
dictionary: 'dict.txt',
classification: 'cls.rten',
orientation: 'orient.rten',
},
});
// Enable orientation correction on demand
const results = await detectText(
{ uri: 'file:///path/to/sideways_document.jpg' },
{
orientation: true, // Fixes 90°/270° whole-page rotation
classification: true, // Fixes 180° upside-down text lines
}
);