Tesseract and Llama 3.2: Linux OCR pipeline tutorial
Spanish Linux OCR guide combining ImageMagick, Tesseract and local Llama 3.2 via Ollama, with cleanup prompts for code, tables and prose.
Player not loading? Watch on YouTube
In this Spanish-language episode, Lorenzo explains a Linux OCR workflow for extracting text from screenshots, photographed documents and scanned PDFs. ImageMagick prepares the image, Tesseract extracts the text, and Llama 3.2 through Ollama corrects recognition errors. The episode describes how to use a local LLM for this final step; the description says the workflow keeps data off external servers.
The preprocessing discussion covers grayscale conversion, contrast normalization, thresholding, deskewing and sharpening. Lorenzo explains the move from ImageMagick 6's convert command to the magick command in version 7. He recommends adjusting the pipeline to the image, including enlarging small text before thresholding and trying median 3 for document photos. His reported accuracy improvements are observations from his experiments, not a general benchmark.
The Python script ocr_ai.py uses heuristics to distinguish code, tables and prose, then adjusts preprocessing and the correction prompt. Code prompts ask for restored indentation without invented lines or renamed variables. Table prompts preserve rows, columns and empty cells; prose prompts correct characters and punctuation without changing meaning.
Automation options include watching a directory with inotifywait and saving extracted text beside each image. Clipboard output uses wl-copy on Wayland or xclip on X11. Lorenzo also discusses custom word dictionaries and OCRmyPDF for adding a searchable text layer to scanned PDFs.