File size: 5,030 Bytes
ae350f1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
---
license: agpl-3.0
library_name: ultralytics
pipeline_tag: object-detection
tags:
  - yolo11
  - oriented-bounding-box
  - obb
  - book-spines
  - bookshelf
  - libraries
  - hebrew
  - ocr-preprocessing
---

# StairsCutter: cut every book spine out of a shelf photo

StairsCutter finds each book spine in a phone photo of a bookshelf, as a **turned rectangle** that follows the book's own
lean, so every spine can be cut out straight and read on its own. It is a YOLO11n-OBB model (2.7 M weights, 5.7 MB) that
takes **about 0.05 s per photo on a CPU** (the fitter adds about 0.3 s). With it comes **the fitter**, a small MobileNetV3-Small model (2.7 M weights) that
moves each cut to the book's own two long edges, so a cut does not take a sliver of the neighbouring book.

<p align="center"><img src="examples/outlines.jpg" width="420" alt="A shelf of leaning Hebrew books, each spine outlined by a turned rectangle"></p>

Both run in production in [Seferehov](https://github.com/amih/seferehov) ([seferehov.com](https://seferehov.com)), a shared
map of free street libraries where readers photograph a shelf and local AI models read the books on it. Trained and
measured on one GTX 1080 (8 GB) from 2016.

## Use it

```bash
pip install -r requirements.txt
python cut_spines.py examples/shelf.jpg out/
```

This writes `out/spine-NN.jpg` (each spine cut straight, length vertical), `out/outlines.jpg` and `out/spines.json`
(corners as fractions of the photo, and confidence). It runs the app's own rules around the model
(`spine_server.py`, `fitter_app.py`): a box found twice is kept once; a box cut off by the photo's edge is kept only
when what shows is still spine-shaped; then the fitter refits every cut.

The model alone, with Ultralytics:

```python
from ultralytics import YOLO
r = YOLO("stairscutter.pt").predict("examples/shelf.jpg", imgsz=1280, conf=0.25)[0]
print(r.obb.xyxyxyxy)   # four corners of each spine
```

## How well it works

Measured on **test v2**: 30 shelf photos, 338 spines whose outlines a person checked by hand, never used in training.
A cut is "right" when it holds the whole spine and no more than a sliver of its neighbours.

| Cutter | Spines cut right (of 338) |
|---|---|
| A vision-language model (Qwen3-VL 8B) asked for boxes, the app's way before 18 Nov 2026 | 15 of 55 on an earlier 55-spine test |
| AnchorCutter (YOLO11n-OBB, the app's first cutter, 18 Nov 2026) | 293 |
| **StairsCutter** (with the app's rules) | **303** (27 won, 17 lost against AnchorCutter) |
| **StairsCutter + the fitter** (in the app since 28 Nov 2026) | **316** (13 fixed, none broken) |

On leaning rows, its reason for being: 4 of 7 leaning spines right (AnchorCutter: 0), and 7 of 14 spines that
AnchorCutter merged with a neighbour. In the app, the cutter took the shelf-reading benchmark from 46 to 49 of 58 books
found and from 95 to 62 seconds per book found ([fixed-9](https://github.com/amih/seferehov/tree/master/bench/fixed-9),
9 photos, public).

## Training

- **Start:** YOLO11n-OBB (Ultralytics), first trained on 36 photos whose 339 spines a person outlined by hand, then
  on approved outlines from the app (64 photos, 455 spines).
- **Synthetic shelves:** 3,000 shelves made from real spines pasted with rendered titles, with book covers as
  distractors (lab 050–051: real data alone cut 10 of 55 right, with the synthetic shelves 41 of 55), then 3,000
  "physics" shelves where books lean and press on each other.
- **StairsCutter itself:** 30 more rounds on leaning rows with staircase tops and bottoms, and runs of look-alike spines
  (lab 077), from the 073 weights.
- **Real photos** come from public street libraries photographed by the app's readers, and the author's own shelves.
  Other readers' home shelves are never used.
- **The fitter** (lab 081): trained on synthetic shelves (the 3,000 physics shelves and 600 scenes of thick and thin
  look-alike spines), with each cut shifted and turned a little, so it learns where the book's two long edges really
  are. It sees the cut widened by 25% on each side, plus its top and bottom strips.

What did not work, for the curious: bigger YOLO models (11s, 11m) and larger input cut fewer spines right; big
vision-language models (Gemma, Moondream, Ministral, Qwen 8B) cut 0 to 13 of 101; classic edge detection confused
letters with edges.

## Limits

- **Books lying flat** are not cut (it learned standing spines).
- Spines cut off by the photo's edge are left out when too little shows.
- Very thin spines next to each other are sometimes taken as one.
- Trained mostly on Israeli street libraries (Hebrew and some English books). It does not read; pair it with a reader
  (the app uses Qwen3-VL 8B, PaddleOCR Hebrew, and [ScoutReader 2](https://huggingface.co/amih/scoutreader-2)).

## Licence and credit

AGPL-3.0, like the YOLO11 code it was trained with and like Seferehov. Made by Ami Heines with Claude Code, in the
Seferehov lab. Questions and results: [Discussions](https://github.com/amih/seferehov/discussions).