Skip to content
activeAIStarted: Sep 1, 2026

Khata2Sheet AI: Local OCR & Bengali Ledger Digitizer

A local-first document processing pipeline that extracts handwritten and printed Bengali khata ledger entries into structured Excel and Google Sheets without cloud API costs.

Technology Stack

PythonOpenCVTesseractFastAPIPandas

My Role

Solo Developer

System Architecture
  1. 1Ledger Camera Capture
  2. 2Image Preprocessing (Bilateral Filter / Perspective Warp)
  3. 3Bengali OCR & Bounding Box Extractor
  4. 4Tabular Structure Reconstruction Engine
  5. 5XLSX & Sheets Exporter
  • 1Ledger Camera Capture──▶2Image Preprocessing (Bilateral Filter / Perspective Warp)
  • 2Image Preprocessing (Bilateral Filter / Perspective Warp)──▶3Bengali OCR & Bounding Box Extractor
  • 3Bengali OCR & Bounding Box Extractor──▶4Tabular Structure Reconstruction Engine
  • 4Tabular Structure Reconstruction Engine──▶5XLSX & Sheets Exporter

Overview

In Bangladesh, millions of retail pharmacies, grocery shops, and small businesses still maintain their primary credit ledger (baki khata) on physical paper notebooks. Manual transcription into accounting software or spreadsheets takes hours each week and frequently introduces calculation errors.

Khata2Sheet AI is an open-source, local-first document processing engine that takes a mobile photo or scan of a traditional Bengali ledger page, rectifies lighting and perspective skew, extracts row-level transaction records, and exports clean, validated tabular data into CSV, Excel, or Google Sheets.

Architecture & Processing Pipeline

  1. Perspective Rectification: Scanned pages are rarely flat. The pipeline uses OpenCV to detect document boundaries, compute the homography matrix, and warp the image into an orthogonal 300 DPI flat plane.
  2. Adaptive Binarization: Traditional retail notebooks use varied ink colors (blue ballpoint, red ink, pencil) on low-grade paper. Adaptive thresholding separates ink strokes from paper fiber noise.
  3. Column Segmentation: Spatial clustering groups text tokens into Date, Customer Name, Description, Debit, Credit, and Balance columns.
  4. Bengali Numeral Normalization: Converts Bengali digits (০-৯) to standard numeric types, computes running balances, and verifies arithmetic consistency across rows.

Why Local-First Matters

Small business financial data is sensitive. Uploading unredacted customer debt lists to public cloud vision APIs compromises merchant privacy and incurs per-page billing costs. Running the pipeline entirely on local hardware guarantees zero data leakage and $0 ongoing software costs.

Interactive Source Explorer & Live CLI Sandbox

Browse source implementation and execute in-browser sandbox simulation.

GitHub Repo
$python -m khata2sheet.cli sample_memo.jpg --export excel
Source Tree (2 Files)
pipeline.pypython
import cv2
import numpy as np

def preprocess_khata_scan(image_path: str):
    img = cv2.imread(image_path, cv2.IMREAD_GRAYSCALE)
    blurred = cv2.GaussianBlur(img, (5, 5), 0)
    thresh = cv2.adaptiveThreshold(
        blurred, 255, cv2.ADAPTIVE_THRESH_GAUSSIAN_C, cv2.THRESH_BINARY, 11, 2
    )
    return thresh

Project Changelog

Pipeline Conception

Built the initial perspective correction engine using OpenCV contour detection.

Bengali Numerals & Ledger Parsing

Integrated custom dictionary heuristics for Bengali ledger headers and currency amounts.