OCR of documents from photos: detection, correction, and recognition pipeline

A photo of a contract taken with a phone — skewed angle, glare, crumpled paper: standard recognition on such images produces garbage, and the operator rekeys the data manually. We develop an end-to-end recognition pipeline: detection, alignment, correction, and field extraction. The output is structured data, and manual input is reduced severalfold.
Frequently Asked Questions

Why document OCR breaks on photos from a phone

A scan and a phone photo are two different inputs for document OCR. In a scan, the sheet geometry is predictable, lighting is even, and the background is white.

In a photo, all of this must first be restored—and every restoration error travels further down the pipeline and turns into field recognition errors.

The first step is document detection in the image: the algorithm looks for four corners and the sheet boundaries.

But the frame is often taken on a textured table, a folder, or another sheet: the background gradient merges with the paper, the edge is cropped, a finger lies on the corner. If the contour is found incorrectly, the wrong rectangle is straightened next.

Perspective correction recalculates the frame into the sheet plane. When shooting at an acute angle, the top of a line is compressed differently from the bottom; after straightening, the proportions of characters are stretched, and small print in the form header loses legibility.

Narrow characters suffer the most—ones, parentheses, hyphens—and those are exactly what numbers and dates are made of.

Shadows and glare break the very preparation of the image for recognition: local darkening from the phone body creates false filled spots, glare erases the strokes of signatures and stamps.

A crumpled form adds line curvature, and stuck-together pages add overlap from which the recognizer pulls text from the neighboring document.

The output is not an "unreadable file" but plausible errors: 8 instead of 3, two lines merging into one, a lost table row. Such failures are not visible at a glance at the result—so let's break down how this is closed.

What a managed recognition pipeline provides

The share of automatic field extraction is calculated separately for each type: printed details and table blocks require different confidence thresholds.

We do not merge them into a single threshold; instead, we set rules—typical fields go into the system without an operator, and disputed ones enter the review queue.

Recognition is built in layers: Tesseract as one of the engines, alongside area detection, dictionary matching, and checksum validation.

Reducing manual input comes not from lowering thresholds but from sorting the queue: the operator first sees documents with the highest number of questionable fields.

Every confirmation is saved and works as labeling for further training—the share of manual corrections on the same document types falls.

Recognition stability is designed before recognition itself. Boundary detection, perspective alignment, and brightness normalization over local areas remove the class of failures caused by phone photos: glare, skew, shadows, crumpled paper. A document stops going to the operator in full because of one poorly captured corner.

The processing time of a document batch is determined by load distribution: pages run in parallel, unreadable ones are rejected before recognition, and results are cached by image fingerprint. A batch of several hundred photos stops being an overnight task.

The effect is measured on a labeled set—the share of correct extractions, the share of manual corrections, and batch time; every pipeline improvement goes through regression testing.

Recognition approaches: cloud, local environment, hybrid

The choice between cloud and local environment is not a matter of taste but a consequence of data requirements, flow volume, and acceptable response latency. Cloud recognition provides fresh models without your own hardware, but the document leaves your perimeter.

A local environment keeps data inside, but model quality and updates are entirely on your side. A hybrid scheme splits the flow: sensitive pages are processed in the environment, while high-volume typical ones go outside.

In practice, the option is fixed by a routing rule—by document type, confidentiality label, and required response time. Below are the signs by which we distinguish the approaches and where each one begins to have limits.

Option When it fits Limitations
Cloud recognition Disparate document types, low and uneven flow, need a fast start and recognition of handwritten fields Data leaves the perimeter, latency depends on the communication channel, quality changes when the model is updated on the service side
Local processing environment Personal data, trade secrets, regulator requirements to store documents inside You need your own compute capacity, model updates, and quality monitoring—all on you, and startup takes longer
Hybrid scheme Mixed flow: some documents are closed, some are typical and high-volume More complex operation: two environments, a single queue, and a routing rule require separate debugging

We separately check what most often surfaces at acceptance: quality on real scans and predictability of response time under peak load.

For an existing document workflow, we add a measurable bar to each option—the share of fields extracted without manual correction—and use it to compare approaches with each other.

Implementation stages: from sample audit to handover

We work in stages: each next one relies on the confirmed previous one, so a weak point surfaces at its own stage rather than at acceptance. Below is what we do at each step and which result we consider a pass to the next.

  1. Audit of document samples. We collect 150–300 real images from your flow: different cameras, angles, lighting, form wear. From them we record defect classes—glare, perspective distortions, stuck-together text—and agree on the target quality for each field.
  2. Labeling the reference set. On the same samples, we label fields, table boundaries, and key details. We split the set into training and holdout parts so that a single page does not end up in both.
  3. Preprocessing and detection. We align the image geometry, normalize contrast, find document zones, and recognize text and table structure.
  4. Rules and postprocessing. We map values to dictionaries, validate checksums, and cut off logically impossible combinations. A questionable field goes to manual review rather than becoming a silent error.
  5. Validation on holdout data. We calculate accuracy for each field separately and review the worst pages, not just the average result. We move on if key details maintain the agreed level.
  6. Handover of the solution to operation. We deploy it at your site or ours, provide the processing scheme, manual review regulations, access, and instructions, and train your team. For the first month we support it and retrain on new samples.

The boundaries between stages are checkpoints: after each one you see a measurable result and decide whether to continue in the same form.

Configurations, schemes, and regulations in the delivery

The delivery does not end when recognition starts working on your photo flow. All settings, schemes, and rules remain with you as files—the support team changes the configuration for new document types without contacting us.

  • Processing pipeline scheme: image intake, document boundary detection in the frame, perspective alignment, preparation for recognition, field parsing, result validation—with an indication of what is logged at each step and where accuracy is most often lost.
  • Document type dictionary: a list of classes with samples, each with its own set of fields, allowed orientations, and signs of mandatory and optional details.
  • Stage configurations: detection and correction parameters, confidence thresholds at which a document automatically goes to manual review rather than to the database.
  • Labeling regulations: how fields are outlined on reference scans, requirements for background and lighting during capture, and the procedure for adding a new document type without rebuilding the entire logic.
  • Recognition quality control: a set of reference documents with pre-verified values, per-field metrics (character accuracy, share of fully correct details), and a mandatory run after any settings change.
  • Error routing scheme: what happens at low confidence—operator queue, request for a repeat photo, or rejection with a clear reason for the user.
  • Monitoring and log: which events are written, and how to distinguish degradation on individual form types from systematically poor input photos.
  • Operation manual: deployment, updating the type dictionary, and rolling settings back to the previous working set.

Such a kit allows you to develop document OCR on your own and understand why a particular image was recognized the way it was.

Case study: recognition of a contract and delivery note archive

The client is a wholesale supplier with an archive of contracts, invoices, and delivery notes spanning several years: about two hundred thousand pages, some of them phone photos taken at an angle and in poor light.

The current flow is around two thousand documents per month, and before us the details were entered into the accounting system manually: an operator processed a batch in almost a full shift, and discrepancies surfaced only during reconciliation with the supplier.

We built a pipeline: sheet boundary detection and perspective correction, background removal, finding detail zones by document template, recognition, and postprocessing—checksums, verification of the amount in digits and words, normalization of dates and numbering.

Recognition is built on the open-source Tesseract engine with a model retrained on their delivery note templates, and validation rules cut off questionable fields before they enter the system.

Each file receives a content hash: the task is queued for processing exactly once, and a nightly re-upload of the same scans does not trigger recognition again.

A batch of a thousand pages is processed in parallel on several nodes, and only fields where validation rules did not agree go to the operator.

The share of fields that entered the system without an operator grew from 58 to 93 percent.

The processing time for a batch of a thousand pages dropped from half a shift to several minutes, and repeat recognition runs fell from 15 to 2 percent—previously a document was rerun after any template change. The archive was processed in batches without stopping the current document workflow.

What to do if recognition is partially implemented

A partially implemented module usually looks like this: there is a recognition call, but no pipeline around it. The image goes into the model as is, comes back as raw text, and then the document lives in the accounting system separately from what the model saw. On good-quality scans the scheme holds; on phone photos it falls apart.

We break down the loop stage by stage and look for exactly where quality is lost. Most often the failure is not in the model itself but before it: sheet boundaries are not aligned, shadows and glare are not removed, and there are extra objects in the frame.

Replacing the recognition module is the last step, not the first: first we close preprocessing and quality control, otherwise the new model will receive the same garbage at the input.

A separate track is retraining on your own samples. We collect a corpus of real photos, including failures and manual operator corrections, label fields, and measure quality on a holdout sample for each document type rather than by an average number.

Open-source engines such as Tesseract are convenient as a reference and as a base for retraining for your form, font, and capture conditions.

Integration with the current loop is about reliability. Processing must be idempotent, retries after failures must be safe, and each model version must have its own log and rollback. Before switching traffic, we run the new scheme in shadow mode and compare field discrepancies.

Building out the pipeline is cheaper than rewriting it: two or three stages change, and the rest continues to work.

Document OCR: engineers' technical concerns

OCR accuracy is not a single number but a distribution across document types: we calculate it separately by characters and by fields, because a mistaken character in a contract number devalues the entire record, while an extra space in an address does not.

Before recognition comes boundary detection and correction—skew alignment, perspective removal, contrast normalization; without this, the model loses percentage points on shadows and tilt, not on text.

What recognition accuracy can realistically be expected?

On printed forms, field accuracy reaches 97–99%; on phone photos it is lower: glare, blur, and geometry get in the way. We monitor not the average number across the flow but the accuracy of critical details and the share of fields sent for review.

Is handwritten text recognized?

Block letters by hand—yes, predictably. Connected cursive and signatures—no. Such fields are recognized with a reduced confidence threshold and given to the operator, and matching against a dictionary of full names and organization names reduces the number of errors severalfold.

How are stamps and signatures processed?

They are not read as text: presence, position, and overlap with significant fields are detected. If a stamp falls over a detail, the field is marked questionable and goes to the operator first—defects do not travel further through accounting.

How is recognition quality checked?

We maintain a regression set of real scans with reference labeling: before updating the model, we calculate field accuracy, recall, and the number of discrepancies.

To start, several hundred labeled examples per form type are enough; after that the set grows through disputed cases from the flow.

Let's discuss the recognition task and come back with a plan

The analysis starts with samples, not general words: photos from different cameras show exactly where recognition breaks—on capture quality, sheet geometry, or table structure.

So start by describing the task and sending document samples; estimating flow volume without them would be guesswork.

What to send for the analysis:

  • 15–20 samples in the form in which they actually enter the system—scans, smartphone photos, angled shots, with shadows and glare.
  • An estimate of flow volume: how many pages per day on average and at peak, how many document types there are, and how often new ones appear.
  • A list of fields to extract, marking mandatory and optional ones, plus examples of non-standard values.
  • Accuracy requirements for each field and the acceptable share of documents sent to manual review.
  • A description of the systems the result goes to, and restrictions on access, storage, and personal data processing.
  • Examples of what has already failed: previous recognition attempts, rules, and templates that did not work.

In response, we will return an estimate of flow volume in pages and machine hours, the composition of work stages, a preliminary plan with checkpoints, and acceptance criteria on your own samples. Describe the task—we will discuss it concretely and come back with an estimate and plan.

AI Development Areas

Latest works

  • Development of a web application for FEEDME
    Development of a web application for FEEDME
    1393
  • Development of an online store for the company FURNORO
    Development of an online store for the company FURNORO
    1368
  • B2B Advance company logo design
    B2B Advance company logo design
    815
  • Development of a web application for Enviok
    Development of a web application for Enviok
    1139
  • AIDER company logo development
    AIDER company logo development
    1057
  • CRM development for Chasseurs
    CRM development for Chasseurs
    1152