Schema LawSign in with Google

Why Does OCR Get Numbers Wrong? Digits, Dates, Decimals

By Schema LawPublished Updated

OCR gets numbers wrong because a digit has nothing around it to confirm it. A misread letter usually produces a non-word that software or a reader catches. Any digit can follow any other, so a wrong 8 looks as valid as the right 3. Catch the mistakes with arithmetic, cross-references and a character-by-character read against the image.

Why are numbers harder for OCR than words?

Numbers are harder for OCR than words because words carry spare information and numbers carry none. If one letter of "agreement" is doubtful, the other eight settle it. If one digit of 48,310 is doubtful, the other four say nothing about it. Every digit has to be read correctly from its own shape.

Software leans on that spare information too. The documentation for the open-source Tesseract engine says that by default it is "optimized to recognize sentences of words", and it suggests different settings for anyone trying to read receipts, price lists or codes. The help that ordinary prose gets from vocabulary is unavailable to a column of figures.

Four more things work against numbers.

  • Ten shapes built from the same parts. Digits are loops, hooks and straight strokes in different arrangements. A 3 is an 8 with the left side open. A 6 is an 8 with the top right open.
  • Smaller type. Figures live in tables, schedules and statements, which are set smaller than body text and packed between ruled lines.
  • Punctuation inside the value. A comma, a period, a minus sign or a pair of parentheses is part of the number, and each is among the smallest marks on the page.
  • No alarm goes off. Spellcheck underlines "agreernent". Nothing underlines 48,810. Your eye passes over a wrong figure as easily as the software did, because it is a perfectly good number.

The last point is the one to hold on to. Errors in words tend to announce themselves. Errors in numbers stay quiet until someone relies on the figure.

On a promissory note those quiet errors sit in the principal, the interest, and the collateral line. You check the lender's name and the security interest clause as carefully as the dollar figure, because a wrong digit in either place points at a different loan. Recompute any total the note prints.

Which digits and letters get swapped most often?

The swaps follow shape. Digits that differ by one small gap or one short stroke trade places with each other, and digits trade places with the letters they resemble. Which swap you get depends on whether the copy is too heavy, too light or too coarse.

Digit for digit

PairWhat separates themWhat removes the difference
3 and 8Two openings on the left of the 3A heavy copy closes them; a light copy opens an 8
6 and 8The open top right of the 6Ink spread or a coarse scan
5 and 6The gap at the lower left of the 5Ink spread
0 and 8The waist of the 8Low resolution, or a slashed or dotted zero
1 and 7The top bar of the 7Faint print, or a 1 with a long flag
4 and 9An open or closed top on the 4Typeface; some 4s are closed at the top
5 and 3The square top left corner of the 5A light copy that drops the vertical stroke
0 and 6 or 9A short tailFaint print

Digit for letter

DigitLetters it trades withWhere it bites
0O, D, QAccount and policy numbers that mix letters and digits
1l, I, the vertical barAnything typed; subsection labels; column rules read as digits
2ZLicense plates and part numbers
5SUnit and suite numbers such as "5B" and "SB"
6b, GCodes in capitals or in lower case
8BBuilding and apartment labels
9g, qLower-case codes

The copy decides the direction

A dark photocopy thickens strokes, so open shapes close: 3 drifts to 8, and 5 and 6 drift to 8 as well. A pale copy thins strokes, so closed shapes open: 8 drifts to 3, and 0 may break into a pair of parentheses. A coarse scan blurs both ways. Knowing which kind of page you have tells you which wrong digits to hunt for. The post on OCR for a low resolution scan shows how to measure whether a file is coarse.

Typeface matters too. A zero with a slash through it can come back as 8 or as the letter Ø. On old typed pages the typist may really have struck a lowercase L for the digit one, and the post on OCR for typewritten documents explains why.

Errors of count

Not every number error is a swap. Watch for a digit read twice, a digit dropped from a run of identical ones (so 1,000 becomes 1,00), a space opened inside a figure, and two neighboring columns fused into one long number. Counting digits catches these where reading does not.

These pairs are one family among several. The broader list, covering names, citations and small words, is in the section on the error patterns that matter in legal text.

Decimal points, thousands commas and negative amounts

Decimal points, thousands commas and the signs that mark a negative amount are the smallest marks on a financial page and the ones with the largest effect. A lost decimal point multiplies a figure by a hundred. A lost minus sign reverses it. Check the punctuation of every figure you rely on, as well as its digits.

MarkHow it failsExample on the pageExample in the output
Decimal pointDropped1,250.001,25000
Decimal pointCreated from a speck12500125.00
CommaRead as a period, or the reverse1,2501.250
CommaRead as a space12,50012 500
Leading minusDropped, or joined to the previous column-340.00340.00
Trailing minusDropped or read as a stray dash340.00-340.00
ParenthesesRead as 1, l, C or dropped(340.00)1340.001
CR or DR suffixSplit off into the next column340.00 CR340.00
Dollar signRead as 5, 8 or S$125.005125.00
Percent signRead as 96 or as 0/04.5%4.596
Superscript note markerJoined to the figure2,400 with a raised 12,4001

Two of these are worth a closer look.

Parentheses. Accountants write negatives in parentheses. If the brackets are read as the digit 1, a loss of 340.00 becomes a gain of 1,340.001. The extra decimal place is your clue: any amount with three digits after the point, or one, deserves a look at the image.

Color. Some statements print negative amounts in red with no other sign. A black-and-white scan keeps the digits and throws away the only thing that made them negative. No amount of proofreading the text will find that. You need a color copy or the paper.

Damage done after recognition

A correct number can still be ruined on its way into a spreadsheet. Opening a CSV file by double-clicking lets the spreadsheet program guess what each cell is. It strips leading zeros from ZIP codes and account numbers, turns long identifiers into scientific notation, and converts entries such as "3-4" into dates. Import the file and set identifier columns to text. Schema Law exports Excel, CSV and JSON on every plan, the free one included, and the pricing page lists the page limits. Whichever you use, compare a few identifiers in the opened file with the page image.

Quick tests for a column of amounts

  1. Every amount should have the same number of decimal places as its neighbors.
  2. Commas should sit every three digits, counting from the decimal point.
  3. No amount should be wildly larger or smaller than the rest of its column without a reason on the page.
  4. The count of negative entries should match the count you see on the image.

How do misread dates happen, and which ones matter?

Misread dates happen in three ways: a digit inside the date is swapped, a separator is read as a digit, or a month abbreviation is confused with another. The result is nearly always another valid date. The ones that matter are the dates you will count from or rely on to put events in order.

How a date goes wrong

On the pageIn the outputWhat happened
03/15/201908/15/20193 read as 8, giving a real date five months off
3/15/2019311512019Both slashes read as 1
11/07/201311/01/2018Two swaps in one date
Jan. 4Jun. 4"a" read as "u" in small type
Mar 12May 12"r" read as "y" on a faint copy
June 1stJune 1 st or June 15tRaised ordinal split off or read as a digit
Rubber-stamped "RECEIVED MAY 02 2022"Nothing, or fragmentsStamp faint, tilted or over other text

A date that becomes impossible, such as a thirteenth month or a 41st day, is the lucky case, because it can be found by sorting or filtering. Most misread dates are plausible, and plausible errors are only found by comparison.

Which dates to verify every time

Verify against the image any date you will enter in a calendar, a chronology, a calculation of interest or a statement to a court or another party. In practice that means dates of service, filing and receipt, dates of notices, dates of loss or injury, signature dates, and the start and end of any period. How a deadline is computed from such a date is a legal question that depends on the rules of your jurisdiction. The point for document handling is narrower: do not let the starting date be one a machine read and nobody checked.

Ways to catch a wrong date

  • Use the sequence. Entries in a ledger, a docket or a set of medical visits run in order. A date that jumps backward or forward and then returns is suspect.
  • Use the weekday. If the document prints "Tuesday, March 15", check that the date fell on a Tuesday.
  • Use the repeat. Letters carry a date at the top and often again in the text or the fax header. Forms repeat dates beside signatures.
  • Use the span. If a statement covers "03/01 through 03/31", no transaction on it can be dated in August.

Dates written only in digits carry one more risk, and it has nothing to do with recognition. In much of the world the day comes before the month, so 03/04 on a foreign record may be the third of April. The post on OCR for foreign language documents explains how to settle which order a document uses.

Account, case and identification numbers with no room for error

Identifiers are the hardest numbers to check, because no arithmetic applies to them and every character counts. One wrong digit in an account number points to a different account. Verify each identifier you rely on by counting its characters, knowing its format, and reading it against the image one character at a time.

Count first

Before reading an identifier, count it. A Social Security number has nine digits. A given bank's account numbers, a court's case numbers and an insurer's claim numbers each have a set length and pattern. A converted value that is one character short or long is wrong, and you know that before comparing a single digit.

Learn the format

Many identifiers reserve certain positions for letters and others for digits, and some exclude confusing characters by design. The vehicle identification number is a useful example because its rules are published. Under 49 CFR 565.13, a VIN consists of seventeen characters, and the permitted set of letters leaves out I, O and Q. So if converted text shows a VIN containing the letter O, the software has misread a zero, and you know which character to fix.

The same regulations build in a self-test. 49 CFR 565.15 makes position nine a check digit, there to provide a means for "verifying the accuracy of any VIN transcription", and sets out the calculation. A VIN whose check digit does not agree with its other sixteen characters has been miscopied somewhere.

Other identifiers have formats of their own, and some have check digits. Look for the issuing body's published description before you lean on a pattern, and do not assume one court's case number format is another's.

Read it properly

  1. Zoom the image until the identifier fills a good part of the screen.
  2. Break it into groups of three or four and compare group by group.
  3. Read it backward once. Going from the last character to the first stops your mind from supplying what it expects.
  4. Compare every occurrence. An account number printed on each page of a statement gives you several readings. If they disagree, the image decides, not the majority.
  5. Copy, do not retype. Once a value is verified, copy and paste it wherever it is needed. Retyping adds human errors to machine ones.

Take a collision report in a fictional matter, Abara v. Kestrel Freight. The converted text gives the truck's VIN as seventeen characters, one of them the letter O, in a position between two digits. The format rule alone flags it. On the image the character is narrower than the O in "FORD" on the same line, and it is a zero.

Identifiers typed or written into boxes bring layout problems as well, covered in the post on OCR for scanned forms. Page identifiers stamped on a production are their own subject, in the guide on how to OCR Bates numbered documents.

Arithmetic and cross-checks that catch a wrong digit

Arithmetic catches a wrong digit whenever the document states a figure that can be recomputed from others: a total, a subtotal, a running balance, a percentage. Put the converted figures in a spreadsheet, recompute, and compare with what the page prints. Where they disagree, the size of the difference points to the error.

A worked example

A fictional checking statement for a client, Delphine Okoro, converts to this table. The last column is added by you: the previous balance plus deposits minus withdrawals.

DateDescriptionWithdrawalDepositBalance as readBalance recomputed
04/01Opening balance2,410.18
04/03Check 1184635.001,775.181,775.18
04/09Payroll deposit1,902.443,677.623,677.62
04/12Rent1,480.002,247.622,197.62
04/20Utility96.312,151.312,151.31

The recomputed balance on 04/12 is 50.00 lower than the balance as read, and the next row agrees again. Because the following row recomputes correctly from the balance as read, that balance is right and the withdrawal is wrong. A difference of exactly 50 in the tens place suggests 3 read as 8: the rent on the page is 1,430.00.

What the difference tells you

Difference between printed and recomputedLikely cause
5, 50, 5003 and 8 swapped, or 1 and 6, in one place
2, 20, 2006 and 8 swapped, or 5 and 3, or 7 and 9
6, 60, 6001 and 7 swapped
Equals one whole line itemA row skipped or read twice
Twice one line itemA sign lost, so a withdrawal was treated as a deposit
About 99 percent of one figure, or 99 times itA decimal point dropped or added
Divisible by 9Two digits transposed, usually by a person retyping

Checks beyond adding up

  • Words against figures. "Ten Thousand Dollars ($10,000.00)" states the amount twice. Compare them.
  • Summary against detail. The total on a cover page should equal the sum of the schedule behind it.
  • Sequences. Check numbers, invoice numbers and page numbers rise in order. A break marks a misread or a missing item.
  • Rates. Where a page gives a rate, a base and a result, multiply.
  • Counts. "Page 3 of 12" and "14 items" tell you how many of something to expect.

What arithmetic will not catch

Two errors can cancel. A printed total can itself be misread to match a wrong column. Figures that belong to no sum, such as identifiers and stand-alone dates, get no help at all. So arithmetic narrows the search and does not replace the read against the image for the figures you will rely on. The guide on converting a scanned PDF to Excel covers getting tables into a spreadsheet in the first place, and the section on proofreading OCR output against the original gives the full routine. Whatever you find, note which figures were verified and by whom, so the next reader knows which numbers have been checked and which have only been read by a machine.

All posts in Difficult scans