Detect the page number from the scanned photo #2

Merged
clayschaad merged 1 commit from feature/ocr-page-number into main 2026-11-06 14:33:52 +00:00
Owner

Summary

When you scan a photo, the app now also tries to read the printed page number and fills the Page field with it.

  • The crop usually cuts off the header and footer, so a second OCR pass runs on the full, uncropped photo. It starts after the note text is filled in, so the text doesn't appear any later. A "Looking for the page number…" hint shows meanwhile.
  • Only the top and bottom three lines are considered. Recognised forms:
    • a standalone number: 42, — 17 —, [12]
    • a labelled number: Seite 128, S. 12, Page 12, p. 12
    • a number at either end of a short running header on the first line: 12 Erstes Kapitel, Erstes Kapitel 13 (only if the line is at most 8 words and doesn't end in punctuation, to avoid matching body text)
  • Lines with OCR confidence below 60 are ignored, and only pages 1–5000 are accepted.
  • The Page field is filled only if it's still empty, with a "Detected from the photo — please check." hint. Detection failures are silent.

New logic is in client/src/lib/pageNumber.ts (pure function, no OCR dependency); ocr.ts gets recognizePageNumber(); NoteFormPage.tsx wires it in.

Limitations

  • Each scan now runs OCR twice, so the page number appears a few seconds after the text on a phone.
  • If the page number is left inside the crop, it also ends up in the note text.
  • Roman numerals (xii) aren't recognised, since the Page field only takes whole numbers.

Testing

  • Ran 14 sample page layouts through findPageNumber (footer/header/labelled numbers, body text starting or ending with numbers, low confidence, unordered input); all pass. The repo has no test setup, so these aren't committed.
  • npm run build -w client passes
  • Not yet tried with a real photo in the app

🤖 Generated with Claude Code

## Summary When you scan a photo, the app now also tries to read the printed page number and fills the Page field with it. - The crop usually cuts off the header and footer, so a second OCR pass runs on the **full, uncropped photo**. It starts after the note text is filled in, so the text doesn't appear any later. A "Looking for the page number…" hint shows meanwhile. - Only the top and bottom three lines are considered. Recognised forms: - a standalone number: `42`, `— 17 —`, `[12]` - a labelled number: `Seite 128`, `S. 12`, `Page 12`, `p. 12` - a number at either end of a short running header on the first line: `12 Erstes Kapitel`, `Erstes Kapitel 13` (only if the line is at most 8 words and doesn't end in punctuation, to avoid matching body text) - Lines with OCR confidence below 60 are ignored, and only pages 1–5000 are accepted. - The Page field is filled **only if it's still empty**, with a "Detected from the photo — please check." hint. Detection failures are silent. New logic is in `client/src/lib/pageNumber.ts` (pure function, no OCR dependency); `ocr.ts` gets `recognizePageNumber()`; `NoteFormPage.tsx` wires it in. ## Limitations - Each scan now runs OCR twice, so the page number appears a few seconds after the text on a phone. - If the page number is left inside the crop, it also ends up in the note text. - Roman numerals (`xii`) aren't recognised, since the Page field only takes whole numbers. ## Testing - Ran 14 sample page layouts through `findPageNumber` (footer/header/labelled numbers, body text starting or ending with numbers, low confidence, unordered input); all pass. The repo has no test setup, so these aren't committed. - `npm run build -w client` passes - Not yet tried with a real photo in the app 🤖 Generated with [Claude Code](https://claude.com/claude-code)
clayschaad added 1 commit 2026-11-06 14:32:03 +00:00
After the cropped text is recognized, run a second OCR pass on the full,
uncropped photo (the crop usually cuts off the header/footer) and look
for a printed page number in the outermost lines: a standalone number
("42", "- 17 -"), a labelled one ("Seite 128", "p. 12"), or a number at
either end of a short running header on the first line.

The result fills the Page field only if it is still empty, with a hint
asking the user to check it. Failures are silent; the user can still
type the page.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
clayschaad merged commit 316afee730 into main 2026-11-06 14:33:52 +00:00
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: clayschaad/Notes#2
No description provided.