{ "cells": [ { "cell_type": "markdown", "id": "d886f3e1", "metadata": {}, "source": [ "# PDF points and OCR pixels" ] }, { "cell_type": "code", "execution_count": 1, "id": "23bfe87f", "metadata": { "execution": { "iopub.execute_input": "2026-11-01T06:47:02.762063Z", "iopub.status.busy": "2026-11-01T06:47:02.761894Z", "iopub.status.idle": "2026-11-01T06:47:17.587594Z", "shell.execute_reply": "2026-11-01T06:47:17.587227Z" }, "scrolled": false }, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "Loaded DBNet detector (CPU, threads=8)\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ "Loaded SVTR recognizer (vocab=185 chars, CPU, threads=8)\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ "[occular] LM (pure Python): compact_lm.npz (268 MB), unigrams=2010937, alpha=0.5 beta=1.0 beam=100\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "EXTRACTED — PDF points\n", "ДОГОВОР ВОЗМЕЗДНОГО ОКАЗАНИЯ УСЛУГ № 42/ПС\n", "[[156.3, 58.6], [439.0, 58.6], [439.0, 70.2], [156.3, 70.2]]\n", "\n", "OCR AT 144 DPI — image pixels\n", "ДОГОВОР ВОЗМЕЗДНОГО ОКАЗАНИЯ УСЛУГ № 42/ПС\n", "[[311.8, 121.0], [877.5, 121.0], [877.5, 136.8], [311.8, 136.8]]\n" ] } ], "source": [ "from occular import OCRPipeline\n", "\n", "reader = OCRPipeline(deskew=False)\n", "extracted = reader.process_pdf(\"text.pdf\", workers=1)[0]\n", "recognized = reader.process_pdf(\"text.pdf\", force_ocr=True, dpi=144, workers=1)[0]\n", "print(\"EXTRACTED — PDF points\")\n", "print(extracted[\"results\"][0][\"text\"])\n", "print([[round(x, 1), round(y, 1)] for x, y in extracted[\"results\"][0][\"quad\"]])\n", "print(\"\\nOCR AT 144 DPI — image pixels\")\n", "print(recognized[\"results\"][0][\"text\"])\n", "print([[round(x, 1), round(y, 1)] for x, y in recognized[\"results\"][0][\"quad\"]])" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.12.3" } }, "nbformat": 4, "nbformat_minor": 5 }