Skip to main content

SmartKhOCR 🇰🇭

SmartKhOCR is a state-of-the-art Khmer Optical Character Recognition (OCR) and Language Correction engine built with Deep Learning Vision Transformers (ViT) and Khmer phonetic language shaping models.

It provides real-time line-by-line streaming, native PDF multi-page recognition, and contextual Coeng (ជើង) & compound auto-correction.


✨ Features

  • 🚀 Deep Learning Vision Engine: Vision Transformer + CTC/Beam Search specifically fine-tuned on modern document scripts, headers, body text, and complex font styles.
  • ✨ Coeng & Compound Auto-Correction: Context-aware corrector that fixes hanging Coeng (e.g., ឆ្ាំ $\to$ ឆ្នាំ), accidental subscripts (សាល្ា $\to$ សាលា), and missing Coeng compounds (រាជធានីភំពេញ $\to$ រាជធានីភ្នំពេញ).
  • ⚡ Ultra-Fast GPU Streaming: Real-time line-by-line and page-by-page streaming generator (13.9 ms/line CTC decoding on NVIDIA RTX GPUs).
  • 📄 Native PDF & Image Pipeline: Direct multi-page PDF processing with on-the-fly rendering and lightweight RAM footprint.
  • 🔍 Side-by-Side Comparison Studio: Integrated web dashboard with bounding box visualization and parallel Tesseract OCR (khm+eng) benchmark comparisons.
  • 💻 CLI & REST API Ready: Built-in CLI tool and FastAPI Server-Sent Events (SSE) streaming server.

📦 Installation

# Clone the repository
git clone https://github.com/your-username/SmartKhOCR.git
cd SmartKhOCR

# Install dependencies using uv or pip
uv pip install -e .
# or
pip install -e .

🚀 Quickstart (Python API)

1. Basic Image OCR

from SmartKhOCR import SmartKhOCR

# Initialize OCR engine (auto-selects CUDA if available)
model = SmartKhOCR(decode_method="fast")

# Recognize text with Coeng auto-correction
result = model("chapter.png", correct_word=True)

print("Recognized Text:")
print(result.text)

# Save annotated visualization with detected line boxes
result.save("output_annotated.jpg")

2. Multi-Page PDF Processing

from SmartKhOCR import SmartKhOCR

model = SmartKhOCR()

# Process multi-page PDF directly
pages = model("document.pdf", correct_word=True)

for idx, page in enumerate(pages, 1):
    print(f"\n--- Page {idx} ---")
    print(page.text)

3. Real-Time Streaming Generator

from SmartKhOCR import SmartKhOCR

model = SmartKhOCR(decode_method="fast")

# Stream lines in real-time as they are decoded
for line in model("document.png", stream=True, correct_word=True):
    print(f"[{line.box}] {line.text}")

🖥️ Command Line Interface (CLI)

SmartKhOCR installs a command-line tool directly into your environment:

# Run OCR on an image or PDF
SmartKhOCR document.png --correct-word --output-txt transcript.txt --save boxes.jpg

# Export model to high-performance inference engines
SmartKhOCR --export engine       # TensorRT engine
SmartKhOCR --export onnx         # ONNX graph
SmartKhOCR --export torchscript  # TorchScript JIT

🌐 Web Studio & Streaming REST API

SmartKhOCR comes with a real-time web dashboard and SSE streaming API:

uv run fastapi run app_ui.py --host 0.0.0.0 --port 8000
  1. Web Dashboard: Open http://localhost:8000 in your browser.
  2. REST API Streaming:
curl -N -X POST http://localhost:8000/api/ocr/stream \
  -F "file=@document.pdf" \
  -F "correct_word=true" \
  -F "fast_mode=true" \
  -F "compare_tesseract=true"

🏷️ Package Architecture

You can import SmartKhOCR using either convention:

# Direct class import (Recommended)
from SmartKhOCR import SmartKhOCR

# Snake_case module import
from smart_kh_ocr import SmartKhOCR

# Backward-compatibility alias
from khmer_ocr import KhmerOCR

📄 License

MIT License. Designed and developed for high-accuracy Khmer text processing.

Metadata

Release files for smart-kh-ocr 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for smart-kh-ocr 0.1.0
File Size Uploaded
smart_kh_ocr-0.1.0.tar.gz 84.6 MB Details

Built distribution (wheel)

Table of built distributions (wheels) for smart-kh-ocr 0.1.0
File Interpreter ABI Platform
smart_kh_ocr-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 169.2 MB

Release files / smart_kh_ocr-0.1.0.tar.gz

Download URL smart_kh_ocr-0.1.0.tar.gz
Size 84.6 MB
Tags Source
SHA-256 checksum
How to use checksums
5969e5bf359a6b59d8d06dff768b24cb9e72476bd1f8e0d50a417b23fab8b3ee
BLAKE2b-256 checksum
How to use checksums
c5c99db8885e6f7493da1a37dc3330ce55c0135b0a6912ba5c1c7d2d1e7cc310
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.7.20

Release files / smart_kh_ocr-0.1.0-py3-none-any.whl

Download URL smart_kh_ocr-0.1.0-py3-none-any.whl
Size 84.6 MB
Tags Python 3
SHA-256 checksum
How to use checksums
230664e9e25cd2b7a2bc2453bab4e2441cae5a6efcbd0fcbb48c86961bfabc70
BLAKE2b-256 checksum
How to use checksums
ed59a49adeb5cb07490a1b8386e48635f61b2475120051f900738d2ef1dc4e54
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.7.20

Release history Release notifications | RSS feed

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

This release

0.1.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page