When the automatic solver has nothing to hold on to, a person clicks 4–8 building corners in the photo and names the 3D corner each one belongs to. uv run utrecht3d camsolve <photo> --pand <id> --points pts.json turns those pairs into a camera in 1–7 s on the CPU. In the benchmark it lands within 2.5 % of the hand-made camera on all 14 photos, and within 1 % on 9.
- Run
camsolve once without --points. Besides its A/B/C guesses it writes _corners.jpg, a plan of the footprints with every wall corner numbered (the target pand green). - Click 4–8 corners in the photo and write them to
pts.json as [u, v, id]: 12g is the ground point of corner 12, 12t its top, and plain 12 means “somewhere on the vertical edge at corner 12”. - Each id looks up a 3D point in the raw 3DBAG LoD2.2 walls around the pand. These points, the pixel coordinates and a focal length go into OpenCV’s SQPnP, once for each focal-length start.
- Every SQPnP start is refined by robust least squares in up to three lens models. The simplest model wins unless a richer one clearly fits better.
- If the click error is under 0.6 % of the long side, the camera is accepted. The same JSON and overlays as the automatic solver are written, and
best.cam goes on to the projection step.
When to use it
- Procedural façades. Render matching (B2) matches the photo against renders of the textured model. Where the model only has procedural textures, as in most of Leidsche Rijn, it finds nothing to match, and the edge fallback is unreliable there. Go straight to
--points. On seven own phone photos of Het Zand, the automatic run accepted none. - A failed render match: the solve is not accepted, or
_render.jpg (the photo next to the model rendered from the result) does not line up. - A confirm panel that doesn’t fit: none of the A/B/C overlays puts its red and yellow lines on the photo’s party walls and cornices.
What a pts.json looks like
Pixels are measured on the upright photo (after any EXIF rotation). A list or {"points": [...]} both work. The // notes are for this page only; real JSON has no comments.
[[ 412, 233, "1t"], // top of corner 1 (eave)
[ 409, 871, "1g"], // ground point of corner 1
[1530, 262, "2t"],
[1534, 905, "2g"],
[1902, 598, "3"], // somewhere on the vertical edge at corner 3
[ 760, 604, 136274.84, 455620.93], // on a vertical edge at RD x, y
[ 755, 905, 136274.84, 455620.93, 2.6]] // a full RD x, y, NAP z
An id like 12t fixes all three coordinates. A plain 12 or an [u, v, x, y] fixes only x and y: the solver adds that point’s height as an extra unknown. So it gives one equation net, where a full corner gives two. A wall corner seen against the sky is fine to click even if the ground is hidden behind cars.
Where the 3D corners come from
corner_table reads the raw 3DBAG LoD2.2 wall polygons (facade_chain.Ctx: no module replacements, not our built tiles). It covers the target pand and every neighbour whose centroid lies within 22 m. Wall vertices are merged per footprint corner on a 15 cm grid. Each corner column taller than 1 m gets a number, with g = lowest and t = highest wall vertex. The target pand is numbered first, then the neighbours by distance. The numbers don’t depend on which façade is chosen, so a pts.json stays valid between runs. For corners that 3DBAG lacks, give explicit RD/NAP coordinates (for example a BAG footprint corner at street level).
Why at least 4, and why 6–8 is better
- Counting. The camera has 7 unknowns: position x, y, z, yaw, pitch, roll and focal length. Each full corner gives 2 equations, so 4 corners (8 equations) is the minimum, and
_pnp_init refuses fewer than 4 points. - Degenerate layouts. If every click lies on one straight line, the camera can turn about that line without moving any point. If they all lie on one flat wall seen almost head-on, stepping back and zooming in give nearly the same picture, so distance and focal length trade off. Spread the clicks over two walls of a corner, or over ground and eave, and both problems go away.
- Robustness. With 8 equations for 7 unknowns, one misplaced click just bends the camera. With 6–8 clicks (12–16 equations), the soft-L1 loss (scale 10 px) can down-weight it.
- Lens and focal length. Richer lens models are only considered when there are at least 2 equations per unknown parameter: 9 clicks for the shift-lens model, 11 for the free principal point. Without an EXIF focal length, the focal length is also a free unknown and needs the depth spread that only non-coplanar clicks give.
Lens models and the choice
- centred: principal point at the image centre; 7 parameters.
- shift: a level camera (pitch = roll = 0) with a free principal point. This is how architecture photographers kept verticals straight, as in the 1979 RCE scans. A weak term keeps the horizontal shift near the centre.
- free_pp: free principal point and free tilt, for crops of larger photos.
The models are tried in that order. A richer model replaces the current one only if (1) there are ≥ 2·(7 + extra parameters) equations, (2) the current error is above 1.5 px, and (3) the richer one cuts the error by more than 40 % (to below 0.6×). Lens distortion k1 is fitted only with --fit-k1. On RCE 39db9cad, a 1979 shift-lens scan with 11 clicks, the errors are centred 3.56 px, shift 1.72 px and free_pp 1.29 px. Shift wins: it more than halves the centred error, while free_pp does not beat shift by 40 %.
SQPnP, refinement and acceptance
Starts. With an EXIF focal length (35 mm equivalent or focal length plus a sensor guess), SQPnP runs once with that focal length, and a weak prior lets it drift: a 15 % change costs as much as a 3 px error. Without one, SQPnP runs at 0.6, 0.9, 1.3 and 2.0 × the long side. For SQPnP, vertical-edge points are placed at the median height of the full corners. OpenCV’s SQPnP is a globally optimal PnP solver for a fixed, known focal length, so every focal start gives one candidate pose.
Refinement. From each start, scipy.optimize.least_squares (soft-L1, at most 400 evaluations) fits the pose, the focal length, the free heights of vertical-edge points and the lens model’s extra parameters. A soft prior keeps the camera near eye height, 1.6 m above the AHN ground (3 px per metre). Solutions with a point behind the camera are dropped, a model stops trying more starts once it is under 0.15 % of the long side, and the whole fit stops after 6 s.
Edge polish. This runs only for thin point sets (fewer than 18 equations, counting a vertical-edge point as one) when time is left. The camera is nudged onto the photo’s line segments with the clicks as anchors. The polish is kept only if the click error stays below max(1.5×, 0.3 % of the long side) and more model edges land on image lines. --polish forces it.
Acceptance. The camera is accepted when the click error (rms per image axis) is under 0.6 % of the long side; otherwise its status is confirm. Unlike render matching, the points path makes no automatic re-render check. Check _overlay.jpg by eye, and later the projected façade.
Benchmark (pts2, 2026-11-29)
The error is measured against hand-made cameras: a 6 × 6 grid on the target façade is projected with both cameras, and the rms gap is given in % of the long side. For 10 photos the clicks were synthetic: the first 6 numbered corners projected with the hand camera, plus 2 px Gaussian noise. The 4 Moreelsepark photos (highlighted) use an agent’s real 6–11 clicks.
| case | clicks | error % | Δpos m | Δyaw ° | f ratio | s |
|---|
| og199 | 6 | 1.04 | 0.23 | −0.07 | 1.002 | 3.7 |
| og222a | 6 | 0.86 | 0.10 | 0.33 | 0.997 | 1.2 |
| og226 | 6 | 1.45 | 0.57 | 0.44 | 0.945 | 1.3 |
| og226b | 6 | 0.08 | 0.05 | 0.00 | 0.998 | 1.3 |
| hs3 | 6 | 2.28 | 0.49 | −1.38 | 1.025 | 1.5 |
| hs1 | 6 | 0.21 | 0.01 | −0.07 | 0.996 | 1.3 |
| rce86 | 6 | 0.50 | 1.22 | −0.29 | 0.981 | 1.7 |
| zadelstraat | 6 | 0.91 | 0.44 | 0.33 | 0.987 | 4.2 |
| het_zand | 6 | 1.73 | 0.75 | −0.46 | 1.010 | 2.7 |
| groenedijk | 6 | 0.47 | 2.29 | −0.65 | 0.924 | 3.2 |
| HUA 824223 | 8 | 0.15 | 1.42 | 0.03 | 0.973 | 5.6 |
| Panoramax 51434ad5 | 7 | 0.74 | 0.66 | 0.02 | 0.974 | 1.6 |
| RCE 39db9cad | 11 | 0.18 | 0.35 | 0.49 | 0.989 | 3.3 |
| RCE f8f857a7 | 6 | 1.70 | 3.38 | −1.19 | 0.919 | 2.1 |
Result: 14/14 within 2.5 % (worst 2.28 %), 9/14 within 1 %, all accepted, median 2 s. On the correct ones the median camera offset is 0.44 m and 0.29°. For comparison, the automatic solver (render matching first, v6) got 8/14 within 1 % in a median of 66 s. A camera 1–3 m off can still put the façade within 0.5 % (groenedijk: 2.3 m, f ratio 0.92), because stepping along the viewing direction and changing the focal length nearly cancel out. The f8f857a7 scan is the weakest: its 6 clicks barely fix a camera even by hand.
Level the photo first
Since 2 Dec 2026 every photo is levelled before its camera is solved. A phone photo held a few degrees off gives a tilted texture: on Vogelvlinderweg 13/15 the brick courses and window heads ran 3–4° off level. The roll is measured from the vertical vanishing point of the photo’s own vertical edges (corners, downpipes, jambs; vertical_vp_roll), and the photo is rotated into a new _level file (the original is never overwritten). The clicks and the camera solve then run on that file. After projection, tilt_check rectifies the crop at 1 cm, finds line segments (OpenCV LSD) and measures the median deviation of near-vertical and near-horizontal segments; it warns above 1°, and a front is accepted only within 0.5°. Where four hand picks leave a small tilt, level_fit refits the homography to the picks and the photo’s own lines (verticals map to ds = 0, horizontals to dz = 0, soft-L1). Vogelvlinderweg 151118: roll −3.80°, rectified verticals / horizontals −1.76° / −3.29° before, 0.00° / 0.00° after (src/utrecht3d/rectify_check.py).
| input | 4–8+ clicks: [u, v, id] · [u, v, x, y] · [u, v, x, y, z] |
|---|
| 3D corners | raw 3DBAG LoD2.2 walls, target + neighbours ≤ 22 m |
|---|
| PnP | cv2 SQPnP, one start per focal (no RANSAC) |
|---|
| focal starts | EXIF f, or 0.6 · 0.9 · 1.3 · 2.0 L |
|---|
| refine | least squares, soft-L1, f_scale 10 px, ≤ 400 evaluations |
|---|
| priors | eye height ground + 1.6 m (3 px/m) · EXIF f ±15 % ≈ 3 px |
|---|
| lens models | centred → shift → free_pp |
|---|
| richer model if | ≥ 2·(7+k) eq., current > 1.5 px, new < 0.6 × current |
|---|
| early stop / time cap | < 0.15 % L / 6 s |
|---|
| edge polish (auto) | < 18 equations and time left |
|---|
| accepted | click rms < 0.6 % of L |
|---|
| benchmark | 14/14 ≤ 2.5 %, 9/14 ≤ 1 %, median 2 s |
|---|
| L | long side of the photo in px |
|---|
Open data: 3DBAG LoD2.2 walls (corner table), AHN DTM (eye height), BAG footprints (explicit corners), photo EXIF. Benchmark photos: Wikimedia Commons, Het Utrechts Archief, RCE beeldbank, Panoramax, own photos.