venv, Tesseract OCR with the language pack you need, ImageMagick (v6 uses convert, v7 uses magick), one or two sample scans with a hand-typed transcription, and — for the neural option — transformers + PyTorch or python-doctr. Optional GPU speeds up neural models; exact hardware requirements per model are on its model card — check the documentation..txt, so quality is measured, not guessed..txt per page into out/.python3 -m venv ocr-env && source ocr-env/bin/activate
pip install --upgrade pip && pip install pillow jiwer pytesseract python-doctr[torch] transformers torch
sudo apt-get install -y tesseract-ocr tesseract-ocr-eng imagemagick
mkdir -p scans gt out && tesseract --list-langsDetails and checks are in the steps below. On Windows use WSL2 and run the same commands inside it.

python-doctr and transformers in their docs.tesseract-ocr-eng, tesseract-ocr-deu, etc.). Package names differ per distro.What to do: create the working tree, convert each scan to grayscale, deskew it, and type a reference transcription by hand.
Why: OCR quality collapses on skewed, colored or noisy scans, and every later decision (which engine, which settings) depends on comparing output to a reference text.
Example:
mkdir -p scans gt out
magick scans/page-001.jpg -colorspace Gray -deskew 40% -sharpen 0x1 scans/page-001-clean.tif
# ImageMagick 6: use `convert` instead of `magick`-deskew 40% asks ImageMagick to search up to 40 degrees of rotation and straighten the page; -sharpen 0x1 restores edge contrast lost to blur.
Then transcribe the page into gt/page-001.txt (UTF-8, same basename as the scan). Keep line breaks as they appear on the page — historical abbreviations, long s (ſ) and ligatures included.
How to check: run identify scans/page-001-clean.tif. You should see TIFF, a size close to the original, and 8-bit grayscale. Open the file and confirm the text lines are horizontal.
Checklist before moving on:
scans/.txt in gt/
What to do: choose an engine from the table, run it on the clean TIFF, and write output to out/.
Why: engines differ in what they were trained on. Printed 19th-century type and cursive handwriting are different problems, and no single engine wins on both.
| Engine | Handwriting | Old printed text | How it runs |
|---|---|---|---|
| Tesseract (LSTM mode) | weak on cursive, usable on neat hands | strong with the right language pack | local CLI, `--oem 1` |
| Kraken | built for historical and handwritten scripts | good with a segmentation model | local CLI, needs a model trained on your script |
| TrOCR (Hugging Face Transformers) | trained on handwritten line images | line-level only | local Python, one text line per call |
| docTR | mixed print/handwriting | good | local Python, does detection + recognition |
| Transkribus | strongest option for archival handwriting | — | hosted service; check pricing and limits on the vendor site |
For an overview of which model families are current, see Best AI models and neural networks in 2026.
Example — Tesseract full page:
tesseract scans/page-001-clean.tif out/page-001 -l eng --oem 1 --psm 6--oem 1 forces the LSTM engine (no legacy engine fallback), --psm 6 tells Tesseract the page is one uniform block of text — right for a single-column letter, wrong for a newspaper with columns (try --psm 3).
Example — docTR full page:
from doctr.models import ocr_predictor
model = ocr_predictor(pretrained=True)
result = model(["scans/page-001-clean.tif"])
for page in result.pages:
for block in page.blocks:
for line in block.lines:
print(" ".join(w.value for w in line.words))Example — TrOCR on a single cropped line (it expects a line image, not a whole page, so crop first or use docTR's detector):
from PIL import Image
from transformers import TrOCRProcessor, VisionEncoderDecoderModel
processor = TrOCRProcessor.from_pretrained("microsoft/trocr-base-handwritten")
model = VisionEncoderDecoderModel.from_pretrained("microsoft/trocr-base-handwritten")
image = Image.open("scans/line-001.png").convert("RGB")
pixel_values = processor(images=image, return_tensors="pt").pixel_values
ids = model.generate(pixel_values)
print(processor.batch_decode(ids, skip_special_tokens=True)[0])Model IDs and available checkpoints change — copy the exact one from the model card.
How to check: head -20 out/page-001.txt should show readable words in the right order. If you get one giant line of garbage, the page layout confused the segmenter: re-run with --psm 3 or feed line crops instead.

What to do: score the output against gt/page-001.txt, change one thing at a time, and only then hand the remaining text to a language model for cleanup.
Why: CER turns “looks better” into a number. Most OCR errors come from one stage — binarization, segmentation, or recognition — and you can only tell which by measuring.
Example:
import jiwer, pathlib
reference = pathlib.Path("gt/page-001.txt").read_text(encoding="utf-8")
hypothesis = pathlib.Path("out/page-001.txt").read_text(encoding="utf-8")
print("CER:", round(jiwer.cer(reference, hypothesis), 4))
print("WER:", round(jiwer.wer(reference, hypothesis), 4))jiwer computes Levenshtein distance over characters (CER) and words (WER). Record the baseline number, change one setting (e.g. --psm 3 instead of 6, or a sharper binarization), re-run, compare. We publish no target CER here because it is document-specific — treat your first score as the baseline and only accept changes that lower it.
For leftover, clearly systematic mistakes (broken ligatures, rn for m), a local language model can fix spelling without seeing the image. Set it up with How to connect n8n to a local LLM: step-by-step private automation setup with Ollama and constrain the prompt: “fix OCR errors only, keep line breaks and original spelling of names”.
How to check: the script prints a CER between 0 and 1, e.g. CER: 0.0812. After your post-correction pass, run the same script on the corrected file — the number must go down. If it goes up, the model rewrote historical spellings; revert.
Problem. Tesseract runs but finds no language data.
Error: Tesseract couldn't load any languages!TESSDATA_PREFIX points to the wrong directory.sudo apt-get install -y tesseract-ocr-eng), then verify with tesseract --list-langs --tessdata-dir /usr/share/tesseract-ocr/5/tessdata. The path differs per distro — locate it with dpkg -L tesseract-ocr-eng | grep tessdata.Problem. The neural model cannot download its weights.
OSError: We couldn't connect to 'https://huggingface.co' to load this fileexport HF_HOME=/data/hf-cache, then set TRANSFORMERS_OFFLINE=1 before running the script.Problem. A full page kills the GPU.
torch.cuda.OutOfMemoryError: CUDA out of memory. Tried to allocate 2.00 GiBmodel.cpu() / device="cpu"), or crop the page into lines first and process them one by one. Batch size is not the only lever — resolution is.You now have a cleaned page set, a measurable OCR baseline in CER, and at least one engine producing per-page text files. Next, extend the same loop to your handwriting engine of choice and wire the corrected output into a retrieval pipeline — the indexing side is covered in How to build an AI shopping assistant on a local model, whose document-loading step applies to any archive.
Can Tesseract read handwriting?
Only neat, regular handwriting. Its LSTM models are trained mainly on printed type; for cursive archival pages use Kraken with a script-specific model, TrOCR on line crops, or a hosted service such as Transkribus.
Do I need a GPU for handwritten text recognition?
No. Tesseract and Kraken run on CPU. Neural models like TrOCR and docTR run on CPU too, just slower per page; a GPU mainly shortens the loop when you re-run hundreds of pages.
How accurate is OCR on 18th-century documents?
It depends on the hand, the paper and the language, so any single number is meaningless. Build a 1–2 page ground truth, compute CER with jiwer, and treat that as your only reliable benchmark.
Which is better: a cloud OCR service or a local model?
A hosted service wins when you need a model already trained on a specific archive and cannot train one yourself; local engines win on cost control, privacy and unlimited re-runs. Hosted pricing and page limits change — check the vendor site.
Status: practical guide. Some statements come from vendors; verify in your environment.
Time to complete: 45–60 minutes Difficulty: Intermediate
Machine data: Citation Map JSON · JSON-LD · Semantic Embeddings — separate stage.
| Entity | Type | Role |
|---|---|---|
| распознавание рукописного текста нейросеть | тема/инструмент | упоминается в заголовке, TL;DR или разделах гайда |
| ocr старинных документов | тема/инструмент | упоминается в заголовке, TL;DR или разделах гайда |
| как оцифровать рукопись | тема/инструмент | упоминается в заголовке, TL;DR или разделах гайда |
| нейросеть для чтения архивных документов | тема/инструмент | упоминается в заголовке, TL;DR или разделах гайда |
| распознавание текста со скана ии | тема/инструмент | упоминается в заголовке, TL;DR или разделах гайда |
| Windows | платформа/технология | упоминается в заголовке, TL;DR или разделах гайда |
| Linux | платформа/технология | упоминается в заголовке, TL;DR или разделах гайда |
| macOS | платформа/технология | упоминается в заголовке, TL;DR или разделах гайда |
| Python | платформа/технология | упоминается в заголовке, TL;DR или разделах гайда |
No independent confirmation is provided; source claims and editorial conclusions are separated below.
| Source | Type | Role |
|---|---|---|
| huggingface.co | внешний источник | ссылка из тела гайда |
Cite as: AI Release. Как распознать рукописный текст и старинные документы нейросетью: выбор модели и настройка OCR. ai-release.org.