Skip to content
undan

Blog

· written up on October 27, 2026Tried

Better the whole photo than a wrong crop

The scanner in the phone app should be fast and never get it wrong. The second part is harder — a hand in the picture, pages that look alike, and seventeen models for four corners.

Undan's phone app now has the same eight areas as the desktop. Seven of them work: documents, inbox, notes, mail, calendar, tasks and contacts. Only the AI is still a placeholder on the phone, and there is no iOS version yet. What the app can do is in the help.

One part that does already feel almost the way I want it to be: the scanner.

Lesen, prüfen, Fertig.

Why a scanner of its own

Until now I photographed paper with Genius Scan, a separate app. Undan itself only had the system camera: no outline, no cropping, every page shrunk to 1,600 pixels. On A4 that's about 140 dpi; text recognition wants 300.

I want a scan to land straight in the inbox: put the sheet down, turn the page, Done — and the computer reads it and suggests a name and where it belongs. For that Undan needs its own camera that finds the sheet, straightens it and writes a proper PDF: black and white at 300 dpi, colour at 200.

What “feels right” means

Two things at once: fast and safe. Fast means I can put sheets down as quickly as I turn pages. Safe means no page is missing, none is there twice, none is cropped wrongly.

  • The auto shutter is the main way, the way I know it from Genius Scan. The outline searches visibly and flickers a little while nothing fits. Once it holds, the ring around the shutter fills, the screen flashes white, and the next sheet can come.
  • By hand works too, with the shutter button or the volume keys. Then the camera stops and shows the corners to confirm — by hand I can't know whether the edges were found.
  • No shutter sound, just a short vibration.
  • Never the same sheet twice.
  • Done doesn't wait. Every page is computed while I keep scanning; Undan writes the PDF afterwards in the background. On the first try with seven or eight pages, Done took too long.
  • Better the whole photo than a wrong crop. If Undan isn't sure about the corners, it takes the whole photo. I see that straight away in Review and drag the corners into place. A wrong crop, on the other hand, cuts off a piece of the sheet or leaves a strip of table — and that may only show when I need the document.

Three things that were harder than I thought

The hand in the picture

On the second try I scanned a lever-arch file, 28 pages: phone held still above it, turn the page, the auto shutter fires. Sometimes it flashed, I turned the page, and then it flashed again. The photo was taken later, and my hand was in it. On seven pages it was in the picture — and for exactly those seven the automatic filter picked “colour” instead of black and white. Because of the skin.

One reason: the screen said “captured” at the moment the camera decided to take the picture. In low light, though, the camera first meters with a pre-flash and then exposes with the main flash, half a second to a full second later. I saw “done” and turned the page. Now the screen flashes only when the camera actually exposes; until then it says Capturing ….

The same sheet or a new one?

“Never the same sheet twice” means Undan has to recognise a sheet. The first attempt was a coarse fingerprint, the sheet averaged into 8 × 8 squares. In the file that wasn't enough. Pages from the same sender, laid out the same way, look almost identical in 64 squares, and even more so under the torch, because the cone of light falls the same way on every page. I held the phone still, turned the page — and nothing happened. I had to lift the phone briefly first.

The fine comparison lays a grid of 128 × 90 cells over the sheet, takes out light and shadow and compares in 24 tiles. What counts is the least similar tile that has something on it: two invoices differ in one place, not everywhere. Measured on 215 pages plus the 28 from the file, the same sheet never scored below 0.48 and a different one never above 0.16. The line is at 0.40.

Only twins score higher: two invoices from the same sender that differ in a few digits. In the file that was 20 of 253 pairs, and they were never next to each other. If you scan pages like that back to back, switch off The same sheet only once.

Good on the test bench, taken out on the phone

Against the hand in the picture I built a hand detector: skin reaching into the sheet from the edge. On the test bench it found 297 of 306 painted hands, 97 per cent, and all seven real pages with my hand. On the phone it kept seeing a hand where there was none. I took it out again.

What helped more was simpler: a short pause after every capture, one second by default, adjustable — time to turn the page. If a finger holds the sheet down at the bottom, it's in the picture. That's fine; I know it'll fire then. The short pause between two captures is really all it takes.

The four corners

Finding a sheet means finding four corners. The first detector is classic geometry — edges, areas, straight lines — in plain Kotlin, without OpenCV, so the same code can run on iOS later. It's the fallback, and it lays the edges precisely on the final photo.

Next to it sits a small network of our own: 634,534 parameters, 1.3 MB. It ships with the app and runs on the phone, offline. I measured it on SmartDoc, 300 frames from phone videos with known corners, which never go into training. The classic detector got 133 sheets right there, the network on its own 247. But the network was also wrong 42 times, mostly with a sheet on a cluttered desk: one corner on the pile underneath.

So the network doesn't decide alone. Undan checks on the photo whether the edges of the quadrilateral are really there; if not, it takes the whole photo. With that rule the 300 frames give 200 correct crops, 98 whole photos and 2 wrong crops. The classic detector, just as cautious, came to 124, 172 and 4.

I've trained seventeen models so far, A to P, all with the same network. Two made it onto the phone: first C, now P. On real photos P is ahead. Of eleven pages from my phone whose corners I had confirmed, P gets ten, C eight. On photos from Dizaj, a freely licensed collection, it's 254 of 330 instead of 204; on till receipts 36 of 71 instead of 21. On SmartDoc it's almost level: 201 correct instead of 200, but 4 wrong instead of 2.

When is a model better? At first the rule was strict: worse in no group, not by a single image. Then came O and P, the same recipe, just a different random start to the training. Of the eleven confirmed pages they got 6 and 10. The strict rule would have measured chance there, not the recipe. Since then there's a tolerance: in a group of fewer than 100 images a new model may be one image worse, above that 1 per cent.

To be honest: P is slightly flattered. I picked it from eleven runs against the same test sets I now measure it on, and the tolerance came when the numbers were already on the table. Draw enough runs and you'll find one that happens to look good there. What P can really do only shows on scans it has never seen.

That's why every scanned page now remembers which model detected it, and Undan counts where I had to drag corners. Under C it was 30 of 55 pages. That sounds bad and says little: under C there are two lever-arch files, a book and three till receipts — exactly the hard cases. The figure compares days, not models.

Where the data comes from

A network learns from images with known corners. P learnt from computed images — pages on many surfaces, with light, shadows, hands and pens —, from three freely licensed collections of real photos (Dizaj, CORD and till receipts from Zenodo) and from my own scans. The app names the sources under Settings → Licenses and sources.

My scans come in through a switch: Settings → Camera → For developers → Collect training cases, off by default. When it's on, the app puts every finished scan — the photos and the corners, detected and dragged — into a folder on the phone, never into the archive. Syncthing carries it to my computer, but only because I set it up that way. Nothing leaves the phone by itself, and nobody sends us anything. The original photos of each scan stay on the phone for 30 days (Keep originals), so I can still change crop and filter; only the PDF goes into the archive.

There's one open question I don't want to answer alone: should you be able to donate individual scans — exactly the kind I lack, from other phones, other tables, other paper? Such a case is a readable photo of a document. Nothing is decided. Until it is: nothing leaves your phone.

A question for you

What do you scan receipts and letters with — and what annoys you about it? Most of all I'd like to know whether a scanner has ever slipped you a wrong crop that you only noticed later.

All posts