Skip to main content

Attributes

The OCR system is configured through OCRConfig, which provides the following attributes:
AttributeTypeDefaultDescription
languagesList[str]['en']Languages to detect (e.g., [‘en’, ‘zh’, ‘ja’])
confidence_thresholdfloat0.0Minimum confidence threshold (0.0-1.0) for accepting OCR results
rotation_fixboolFalseEnable automatic rotation correction for skewed images
enhance_contrastboolFalseEnhance image contrast before OCR processing
remove_noiseboolFalseApply noise reduction filter to improve text clarity
pdf_dpiint300DPI resolution for PDF rendering (higher = better quality, slower)
preserve_formattingboolTrueTry to preserve text formatting (line breaks, spacing)

Configuration Example

from upsonic.ocr import OCR
from upsonic.ocr.base import OCRConfig
from upsonic.ocr.tesseract import TesseractOCR

# Method 1: Using OCRConfig
config = OCRConfig(
    languages=['eng', 'fra'],
    confidence_threshold=0.6,
    rotation_fix=True,
    enhance_contrast=True,
    remove_noise=True,
    pdf_dpi=300,
    preserve_formatting=True
)
ocr = OCR(TesseractOCR, config=config)

# Method 2: Direct parameters
ocr = OCR(
    TesseractOCR,
    languages=['eng', 'fra'],
    confidence_threshold=0.6,
    rotation_fix=True,
    enhance_contrast=True
)