One of our wholesale buyers orders on a printed sheet: about 250 products in four columns, and a handwritten quantity next to the 18 or so they want this week. They photograph it and send it on WhatsApp. We read it with a vision model and draft the order.

This sheet read badly. On a good day the model got 12 of the 18 quantities right, often fewer, and each miss put a quantity one row up or down, on the wrong vegetable. It rated its own reads anywhere from 12 to 98 out of 100.

The ask was reasonable: when the photo is too poor to read, don't guess. Ask the buyer to send it again in HD and process nothing. It had to be plain pixel math, with no extra model call.

The textbook checks

Every "is this image good enough" recipe uses the same handful of numbers. Variance of the Laplacian for blur, mean brightness for exposure, histogram spread for contrast, a median-filter residual for noise and pixel count for resolution. The OCR-flavoured versions swap in Sobel edge strength, the Otsu gap between ink and paper, and the share of blown-out white or crushed black.

I ran both recipes, with their usual thresholds, over every order photo our buyers had sent in the past 30 days: 738 of them. Here's how many each check would have blocked:

  • Under 2 megapixels: 738 of 738
  • Short side under 800px: 485
  • Bad exposure: 118
  • "Noisy": 114
  • Blurry: 72
  • The general recipe without the resolution rule: 255 (35%)
  • The OCR recipe: 526 (71%)

The resolution rules fail everything, because WhatsApp shrinks every photo to about one megapixel. "Noisy" did fire on the dense sheet, but only because tiny printed text looks like grain. And the bad photo passed every check except resolution, which every photo fails. It was sharp, evenly lit and clean.

So I looked at the photos the checks liked least. The blurriest were product shots, a car and a machine part. The darkest were dark-mode payment screenshots. In 738 photos there wasn't one blurry or dark order slip. People photographing an order they want filled take a decent picture.

The photos weren't bad. They were good photos of something too dense for the pixels available. None of the stock checks measure that.

What was actually wrong

The model's own low confidence didn't point at bad photos either. A crisp printed list scored 55. Mostly a low score meant messy handwriting or a product the catalogue spells differently, and "send it in HD" fixes neither.

The sheet's problem was arithmetic. 250 printed rows in a one-megapixel photo leaves each row about 15 pixels tall. The handwriting is legible. What the model loses is which row a quantity sits on.

That can be measured. Open the ink mask with a long horizontal kernel and only the ruled lines survive. Take the row profile in four vertical strips, so a slightly tilted page still gives sharp peaks, then count the peaks and take the median gap. Do it on both axes, because the sheet often arrives sideways.

lines = cv2.morphologyEx(ink, cv2.MORPH_OPEN, cv2.getStructuringElement(cv2.MORPH_RECT, (w // 25, 1)))
profile = lines[:, strip].sum(axis=1)       # one peak per ruled row
rows, pitch = len(peaks), np.median(np.diff(peaks))

The order sheet comes out at 42 to 73 ruled rows, 12 to 17 pixels apart. A notebook page comes out at about 7: each ruled line is found twice, once at its top edge and once at its bottom. That accident is what makes the two easy to tell apart.

The rule, and what it hits

Block the photo when all three hold: 40 or more ruled rows, 12 to 17 pixels apart, and the read rating itself under 75. Rows alone flagged 46 photos, mostly product cartons and a few forms that read fine. Requiring the low score cut that to 9. All 9 were the 250-row sheet, all 9 were misread, and it fired on no other buyer in the month.

That rule was tuned on the same month it was scored on, so I also ran it over 8,278 older photos from the chat history that it had never seen. With a 10px floor it blocked 4. One was another restaurant's dense order form, the same failure. Three were wrong: a notebook slip, a typed list and a stack of courier receipts, all with rows 10 or 11 pixels apart. Every real hit sat at 12 or more, so that's the floor now.

The check runs alongside the read, so it adds no wait. When it fires, the buyer gets three ways to resend: in HD, as a document (which keeps the full resolution) or closer up.

What I'd reuse

  • Bench a quality gate on your own traffic before shipping it. The stock thresholds describe photography. Ours would have turned away a third of real orders, and caught the bad sheet only because its tiny print looked like noise.
  • Look at what each check flags, not just how many. The "worst" photos were screenshots and product shots. Ten minutes of eyeballing ruled out the whole approach.
  • Measure the failure, not "quality". Our failure was too many rows in too few pixels, and one number described it. A narrow gate you can trust beats a broad one you can't.
  • Keep a holdout, even a messy one. Old chat photos without labels still showed three wrong blocks that the tuning month never would have.