A till receipt is an unpromising document for a computer. It is printed in faint grey on thermal paper that fades in sunlight. It is long, narrow and usually creased, and it has often spent an afternoon in a pocket. The typeface was chosen for cheapness. Every shop lays it out differently, abbreviates items in its own way, and scatters the page with loyalty messages, tax codes and survey invitations.

All the same, you can now photograph one in a dim restaurant and get back, within a couple of seconds, a list of what was ordered and what each item cost. The process has four stages, and a look at each shows where the mistakes come from.

Stage one: cleaning up the picture

The photograph is nearly always taken at an angle, in poor light, with a tablecloth in the background.

First the software finds the receipt. It looks for the edges of a bright, roughly rectangular region and marks its four corners. Then it corrects the perspective, stretching the trapezium seen by the camera back into a rectangle, as if the paper had been scanned flat.

Next it deals with lighting. A shadow across one half of the receipt makes the paper there darker than the ink elsewhere, so a single brightness threshold will not separate text from background. The usual solution is to decide what counts as dark separately for each small area, relative to its surroundings.

The result is a clean, upright, high-contrast image. If this stage goes badly, everything after it suffers. It is the stage the user can help with most.

Stage two: finding and reading the text

Optical character recognition, the conversion of images of text into characters, is one of the oldest problems in computing. Machines to read printed characters were being built in the 1950s. For clean print in a known typeface the problem was largely solved decades ago.

Receipts are harder, and modern systems tackle them in two steps.

Detection. A neural network scans the image and draws boxes round regions that contain text, line by line. On a receipt this has to cope with columns: the item name on the left, the price on the right, sometimes a quantity in between.

Recognition. A second network takes each boxed line and outputs the sequence of characters. It does not cut the line into individual letters first, as older systems did. It reads the line as a whole, in the manner of speech recognition, using the surrounding characters as context.

The context is the strength of the method and also the source of its typical errors. The network has learnt which character sequences are likely. On faint print it will produce something plausible, and it may be wrong.

The classic confusions are between characters that look alike: 0 and O, 1 and l and I, 5 and S, 8 and B, a full stop and a comma. In a word, context sorts them out. In a price, it cannot. 18.50 and 13.50 are both perfectly reasonable prices.

Stage three: working out what it means

At this point the software has lines of text and their positions on the page. It does not yet know which line is the shop's name, which are purchases and which is the total. A receipt might read:

2 FLAT WHT          7.60
AVO TST SRDGH      11.50
  ADD EGG           2.00
SUBTOTAL           21.10
SERVICE 12.5%       2.64
TOTAL              23.74
CARD ****4471      23.74

A person sees at once that there are three purchased items, that the egg belongs to the toast, that the service charge is not an item and that the card line repeats the total. For a machine, none of that is given.

Early systems used rules: a line ending in a number is probably an item, and a line containing the word TOTAL is the total. Rules work until a shop prints "TOTAL SAVINGS" above the real total, or lists a discount as a negative item.

Current systems use models trained on large numbers of labelled receipts. The more recent of these take into account the words, their position on the page and the appearance of the image together. Layout carries a lot of information: prices line up on the right, totals come near the bottom, and an indented line is usually a modifier of the one above. Models that combine text with position do markedly better on documents like these than models that read the text alone.

Large general-purpose language models that accept images can now do the whole job in a single step. Given a photograph and a request to list the items and prices, they return a structured list. They cope well with unfamiliar layouts. They also bring their own risk, which is that when part of the receipt is unreadable they may fill in something likely.

Stage four: checking

A well-built app does not simply trust what it has read. A receipt contains its own cross-check.

  • Do the item prices add up to the subtotal?
  • Does subtotal plus tax and service equal the total?
  • Does quantity times unit price equal the line amount?
  • Is the date a real date, and not in the future?

If the items sum to 21.10 and the receipt says so, the reading is very probably right. If they sum to 26.10, one of the prices has been misread, and the app can flag the lines it was least sure of. This is why some apps ask you to confirm a single figure and others present the whole list for review. It depends on whether the arithmetic closed.

What goes wrong, and why

Faded or crumpled print. The image is simply missing information.

Misread digits. The costly error, since a wrong price changes what somebody owes.

Abbreviations. "AVO TST SRDGH" is read correctly, and nobody at the table can remember who ordered it. The software has done its job, and the receipt itself is still obscure.

Modifiers and multi-line items. The egg may be treated as a separate item, or attached to the wrong line.

Quantities. "2 FLAT WHT 7.60" could mean two at 3.80 or two at 7.60 each. Shops differ.

Discounts, deposits and refunds. Negative lines and lines that are not purchases confuse the totals.

Tax and service. Whether tax is included in the item prices varies by country. An app built for one convention may mishandle another.

Handwriting. A tip written in by hand, or a handwritten receipt from a market stall, is a much harder problem than print.

Unfamiliar languages and scripts. Accuracy is highest for the languages and layouts best represented in the training data.

Reported accuracy for reading individual fields from receipts in public benchmark tests is high, well above 90 per cent for the best systems. That still means that on a receipt with twenty lines, an error somewhere is quite likely.

Getting a good scan

Most errors can be prevented at the moment the photograph is taken.

  1. Flatten the receipt on a dark, plain surface.
  2. Light it evenly. Avoid your own shadow. Daylight from a window is ideal.
  3. Hold the phone directly above, parallel to the paper.
  4. Fill the frame, with all four edges visible.
  5. For a long receipt, use the app's multi-shot option if it has one, in preference to one distant picture.
  6. Photograph it soon. Thermal paper fades in weeks, faster in heat.

Then check three things before sharing the result: that the total matches the paper, that the number of items looks right, and that any price the app has marked as uncertain is correct. It takes ten seconds.

Privacy

A receipt carries more than prices. It shows where you were and when, what you bought, sometimes part of a card number and a loyalty account. Apps that read receipts usually send the image to a server for processing. Their policies on how long images are kept, and whether the purchase data is used for marketing or sold in aggregated form, differ a good deal. Some loyalty and cashback apps exist precisely to collect this data and pay you a little for it. It is worth knowing which kind you are using.

The division of labour

The technology has taken over the tedious part of dealing with a receipt, which is the typing. It has not taken over the part that needs to have been there: knowing that the second bottle was ordered by the far end of the table, that the birthday guest is not paying, or that one coffee was sent back.

So the sensible arrangement is the one most bill-splitting apps have settled on. The machine reads the receipt, the people at the table say who had what, and one of them checks the total against the paper.