{"data":{"slug":"github-xberg-io-xberg-ai-rulez-skills-ocr-pipeline-and-quality-eb30632d2237","title":"OCR Pipeline And Quality","summary":"A comprehensive guide to OCR processing, including backends, preprocessing, caching, and quality assurance.","url":"https:\/\/skillshunter.net\/skills\/github-xberg-io-xberg-ai-rulez-skills-ocr-pipeline-and-quality-eb30632d2237","json_url":"https:\/\/skillshunter.net\/api\/public\/v1\/skills\/github-xberg-io-xberg-ai-rulez-skills-ocr-pipeline-and-quality-eb30632d2237","markdown_url":"https:\/\/skillshunter.net\/skills\/github-xberg-io-xberg-ai-rulez-skills-ocr-pipeline-and-quality-eb30632d2237.md","download_url":"https:\/\/skillshunter.net\/skills\/github-xberg-io-xberg-ai-rulez-skills-ocr-pipeline-and-quality-eb30632d2237\/download","category":{"slug":"software-development","name":"Software & Development"},"editor_note":"The skill focuses on OCR pipelines, including backends like Tesseract, PaddleOCR, and Candle, with preprocessing, caching, and quality assurance. It emphasizes structured conversion, page acceptance, and cache management. The skill does not include general OCR tools or document formatting features.","instructions":"---\ntype: Playbook\ntitle: Ocr Pipeline And Quality\ndescription: \"OCR backends, preprocessing, caches, hOCR, tables and quality comparisons.\"\npaths:\n  - \"crates\/xberg\/src\/ocr\/**\"\n  - \"crates\/xberg\/src\/paddle_ocr\/**\"\n  - \"crates\/xberg\/src\/sceptre_ocr\/**\"\n  - \"crates\/xberg\/src\/candle_ocr\/**\"\n  - \"crates\/xberg-tesseract\/**\"\n  - \"crates\/xberg-paddle-ocr\/**\"\n  - \"crates\/xberg-candle-ocr\/**\"\n  - \"tools\/ocr-measure\/**\"\nx-ai-rulez:\n  kind: skill\n  id: ocr-pipeline-and-quality\n  metadata:\n    name: ocr-pipeline-and-quality\n---\n\n# OCR pipeline and quality\n\nOCR flows through preprocessing, backend execution, structured conversion, page acceptance, and caching. Backend\noutputs are not interchangeable measurements.\n\n## Backends and execution\n\n- All backends implement `OcrBackend`. Tesseract is the default and is bound through the in-repo\n  `crates\/xberg-tesseract` C FFI crate; there is no `leptess` dependency.\n- `OcrBackendType` is `Tesseract | PaddleOCR | Candle | Custom`. Sceptre is selected by name through `Custom`, not a\n  dedicated enum variant.\n- Run blocking OCR work through `tokio::task::spawn_blocking`, minimize runtime\/FFI lock duration, and respect backend\n  resource limits.\n- Check `PageOrientationHandling` before assuming a backend handles rotated input.\n- Validate ISO 639 language codes and required tessdata before execution. Language detection runs after extraction\n  and does not choose traineddata automatically. One exception: when the first Tesseract read of a page is noisy and\n  OSD names Han, the page is read again with `chi_sim` if `osd` and `chi_sim` are installed. OSD alone chooses the\n  script. The retry never downloads a model, and it does not run when `ocr.pipeline` is set. A line takes the second\n  read under four rules (mostly Han letters, a confidence gain, every Latin or digit word kept or replaced by Han\n  letters, word coverage). A page takes the second read only when one third of its lines pass. Table detection does\n  not stop the retry: it is on by default, so a gate on it would make the retry dead.\n\n## Configuration and cache\n\n- Public `types::formats::TesseractConfig` and internal `ocr::types::TesseractConfig` have independent defaults. Change\n  both and keep their synchronization test passing.\n- The OCR cache key combines a build-identity tag, image hash, backend, config hash, and output format. The config\n  hash includes `TESSERACT_RESULT_SCHEMA_VERSION` and the ordered Tesseract variable set and carries no build identity\n  of its own, but it is not the whole key: `OcrCache::generate_cache_key` prefixes `cache_version_tag()`, which hashes\n  `CARGO_PKG_VERSION`, `CACHE_SCHEMA_VERSION`, `env!(\"XBERG_BUILD_ID\")` and the debug\/release bit. Two builds from\n  different commits therefore never share entries.\n- Bump `TESSERACT_RESULT_SCHEMA_VERSION` when unchanged image\/config inputs can produce different output, or disable\n  the cache for an A\/B or revert check.\n- Default preprocessing is 300 DPI, deskew, and Otsu binarization. Auto-rotation, denoise, contrast enhancement, and\n  color inversion are off unless configured. Native PSM defaults to 3; WASM defaults to 6.\n\n## Quality invariants\n\n- Query `confidence_semantics()` before interpreting confidence. Never threshold `Uncalibrated` output using a\n  Tesseract-derived scale.\n- Tesseract font size is typography from hOCR `x_fsize`; Sceptre\/Paddle font size is a geometric detection-box proxy.\n  Do not compare or threshold them as the same quantity.\n- `hocr_font_info=1` is required for Tesseract typography; without it font sizes fall back to 12 pt. Sceptre\/Paddle do\n  not provide hOCR style fractions.\n- `accept_or_reject_ocr_page` can discard an entire page and its structured paragraphs. Compare accepted pages before\n  word counts. A missing dictionary-invalid ratio is unknown, not zero.\n- Precision is the scarce resource on the current benchmark corpus. Require an independently grounded F1 A\/B for\n  recall-oriented rewrites; use the `benchmark-workflow` skill.\n- Measure structural output such as headings and lists in Markdown, not Plain.\n\n## Tables and geometry\n\n- OCR table detection clusters word bounding boxes; it does not detect ruled lines or re-OCR cells.\n- Detect rows, merge words into cell tokens, then detect columns on the merged tokens. Use\n  `reconstruct_table_with_columns`; detecting columns on raw words creates spurious columns for multi-word cells.\n- The PDF OCR raster is normalized to MediaBox-oriented user space. OCR segments carry `rotation_degrees: 0.0`; code\n  reasoning about `\/Rotate` pages must carry page rotation explicitly.\n- Preserve word-level bounding boxes, confidence, and reading order through hOCR parsing and validate a reconstructed\n  grid before emitting Markdown.\n","use_cases":["OCR a scanned document with rotated text using Tesseract","Compare OCR results from different backends for quality assurance","Cache OCR results for faster processing in subsequent runs"],"limitations":["OCR cache entries are unique per build and cannot be shared between different commits","Font size measurements differ between Tesseract and Sceptre\/PaddleOCR","Confidence values should not be thresholded without proper calibration"],"compatibility":[],"setup_tip":null,"sample_input":null,"sample_output":null,"source_url":"https:\/\/github.com\/xberg-io\/xberg\/blob\/95bf61a74390a3ecccaf6356ae874d0a8b26aa9a\/.ai-rulez\/skills\/ocr-pipeline-and-quality\/SKILL.md","source_commit":"95bf61a74390a3ecccaf6356ae874d0a8b26aa9a","license":null,"version":null,"listing_approved_at":"2026-11-15","created_at":"2026-11-14T15:13:07.000000Z","updated_at":"2026-11-15T16:56:51.000000Z","seo_title":"OCR Pipeline And Quality Guide","seo_description":"Learn about OCR backends, preprocessing, caching, and quality assurance in this comprehensive guide.","seo_keywords":["OCR pipeline","OCR quality","OCR preprocessing","OCR caching","OCR backends"]}}