Before this unit: Homogeneous coordinates
What Is a Homography?
How to take a photo of anything flat, a court, a page, a wall, and work out where on it every pixel lies. One pipeline, from painted lines to corners to a 3×3 map to a bird's-eye view, and why a simpler map cannot do it: measured on one frame of a pickleball final, an affine map misses the far sideline by 3.97 m where a homography misses it by 6 cm.
This unit is about taking a photograph of something flat, a court, a page, a wall, and working out where on that surface every pixel lies. The rule that does it is called a homography: a map that moves every point of a flat surface from one view to where it appears in another. It works for any plane and any camera, and for photos taken from one spot while the camera turns. The animation shows the finished result: each player’s feet in the camera view, placed on the court seen from above.

Every lesson is one step of the same pipeline:

- Photo. One frame from a fixed camera, here a pickleball final filmed from behind one corner of the court.
- Find the painted lines. Paint is a thin bright stripe, so it is found as a ridge: a morphological filter keeps what is brighter than its surroundings over a narrow width (the morphology lesson shows the operations). A straight line is then fitted to each stripe.
- Cross them into corners. Two lines meet at one point, even when that point is outside the photo; homogeneous coordinates make that one multiplication.
- Pair each corner with its position on the court. The rulebook fixes the court’s size, so every corner has a known position in metres.
- Choose the map. How many numbers the rule from metres to pixels needs, and why fewer than eight cannot fit a court seen from a corner (lessons 1 and 2; the next section has the short version).
- Solve. Four pairs of points give eight equations, enough for the eight numbers (lesson 3).
- Throw out wrong pairs. One corner paired with the wrong court position, among six, puts the far baseline 17.6 m off. Fit on random small subsets and keep the answer most pairs agree with (lesson 4).
- Use it. Push any pixel through the map to get metres, or pull the whole image through it to see the court from above (lesson 5).
What the outputs are used for
Once you know what to look for, homographies are everywhere a camera looks at something flat, and each use acts on what the map returns:
- Sports graphics and statistics. A player’s feet pushed through the map give a position in metres, and positions over time give distance covered, speed and in-or-out calls. The radar view of a broadcast is the same map.
- Graphics painted onto the ground. An advert or a line that appears to lie on the pitch is an image warped onto the pitch’s plane and drawn under the players:

- Document scanners. Four corners of a page photographed at an angle, moved to a rectangle by one homography, give a flat page that text recognition can read:

- Panoramas. Photographs taken from one spot while turning the camera are related by homographies, which is how panorama modes join them [12]:

- Camera calibration. The standard method photographs a flat chessboard several times; the homography between the board and each photo is what the camera’s focal length and centre are solved from [11].
- And in parking cameras that stitch a top-down view of the car’s surroundings, in projectors that correct a tilted image, and in aerial photos aligned to a map.
A homography is the map that sends every point of a flat surface in a photo to its place on that surface, and a few points you can recognise in both are enough to find it. On a pickleball court seen from behind a corner, the best map without it misses the far sideline by 3.97 m; the homography misses it by 6 cm. Gonzalez and Woods file the same problem under geometric transformations and image registration [7].
Before this
You need homogeneous coordinates. Every map in this unit is a matrix acting on , and the lesson that explains why also measures the vanishing point this unit keeps returning to. Correspondences come from SIFT in a panorama and from painted lines here; the edge detection unit is where finding those lines starts.
The frame everything is measured on
One frame of the 2026 WD Open women’s doubles gold-medal match, filmed by a fixed camera standing behind the near-left corner of the court [9]. Frame 45000, 1920×1080, which is 1,501.5 s into the match.

A court is the best possible object for this unit because its size is written down. The USA Pickleball rulebook fixes it at 13.41 × 6.10 m with the non-volley lines 2.13 m from the net, measured to the outside edge of 5.08 cm lines [8], so every claim below is a distance in centimetres against a published dimension rather than an alignment that looks right.
Twelve points on it have names: where each painted line crosses another. Four of them, the corners of the near half, define the fit in every lesson. A fit through four points reproduces those four with no error, so their error proves nothing. Everything else is the evidence:
| Held-out check | What it must equal |
|---|---|
| NBC, NKC: where the near centre line meets the baseline and the kitchen line | their court positions |
| the near centre line, along its whole length | m |
| the right sideline beyond the net | m |
| the far baseline, where it shows right of the net post | m |
How to write down the map
Step 5 asks how many numbers the rule from court to photo needs. The rule has to send a point in metres to a pixel .
The first rule anyone writes is a 2×2 matrix: , . Four numbers rotate, stretch and shear the whole plane, and adding a shift gives the affine map, six numbers. Both keep parallel lines parallel. On the ground the court’s two sidelines are parallel; in the photo they are 20.35° apart, closing toward the far end. No 2×2 can do that, so the best one misses every corner by 60.4 px, and an affine map fitted through three corners misses the fourth by 3.50 m and the far right sideline by 3.97 m.
The map that fits divides by something that depends on where the point is:
Points far up the court get a larger denominator and shrink toward one spot, the vanishing point, which is how two parallel sidelines can meet in the photo. These eight numbers, written as a 3×3 matrix with a 1 in the corner, are the homography. Four point pairs fix them, and on this court the result misses the far right sideline by 5.95 cm and the near centre mark by 0.47 cm. Lesson 1 works the 2×2 on the court and lesson 2 adds the shift and the division, one column and one row of the 3×3 at a time [2].
Try the whole unit in one move
Pick a point on the court diagram, then the same point on the photograph, four times. The browser solves for the homography on the spot and draws the whole court from the diagram onto the photo. Every lesson below explains one part of what happened.
Frame 45000 of "2026.07.25 WD Open … (Gold Medal match)" by pickleball4you, CC BY 3.0.
Topics
- What a 2×2 matrix does to a picture. Step 5, the simplest candidate: where do four numbers send the plane, what does the determinant measure, and what is the one thing no 2×2 can do to a court?
- Affine and projective: the 3×3. Step 5, finished: one extra coordinate buys translation, and one extra row buys perspective [2]. How much does each buy on a real court?
- Computing a homography: the DLT. Step 6: four point pairs give eight equations in nine unknowns [1]. How is the answer read off, what does normalising the coordinates change [6], and where does the error go?
- RANSAC. Step 7: the DLT trusts every pair it is given. How do you fit a model when a third of the pairs are wrong [5]?
- Warping and blending. Step 8: with the map in hand, how do you move the pixels through it without leaving holes, and how do you combine several frames into one?
The order follows the pipeline. Steps 2 to 4 are measured on the hub and in homogeneous coordinates: the paint is found with a morphological filter and a line fit, and the corners are where those lines cross. The lessons here start at choosing the map.
What the unit measures
Every lesson carries its own numbers. The ones that decide the order the lessons are in,
all from output/alignment_numbers.json, all in centimetres on the court and all on
paint the fit never saw:
| NBC | NKC | near centre line | far right sideline | far baseline | |
|---|---|---|---|---|---|
| affine through 3 corners | 91.6 | 188.5 | 125.6 | 397.0 | 308.8 |
| affine, least squares on 4 | 122.4 | 34.1 | 78.6 | 105.1 | 551.6 |
| homography through 4 | 0.47 | 5.63 | 2.66 | 5.95 | 38.4 |
| homography, least squares on 6 | 0.25 | 3.18 | 2.13 | 8.53 | 31.7 |
| homography through 4, lens corrected | 0.51 | 5.42 | 2.74 | 1.96 | 24.1 |
Two things in that table set up the unit. The step from affine to projective cuts the error by 8× at the far baseline and by up to 195× at NBC, which is lesson 2. And the homography’s worst number, 38 cm at the far baseline, is not a failure of the model: one pixel there spans 8.1 cm of court, against 0.6 cm at the near baseline, so the far baseline’s 38.4 cm is under 5 px. Lesson 3 is about where error goes.
Limitations & caveats
- One camera, one court, one minute. Everything is measured on a single fixed view. The ordering (affine far worse than projective) is geometry and will hold anywhere; the centimetre values belong to this lens, this distance and this angle.
- The far half of the court is mostly not evidence. Seen through the net’s mesh, a painted line turns into a dotted band as wide as the strip searched around it, and a line fitted to a uniform band returns the middle of the strip, which is the prediction it started from. The net region is excluded by a polygon drawn by hand, and the far half contributes only the two stretches of paint that show clear of it.
- The lens is not a pinhole. The near baseline bows by 7.7 px across the frame. A one-parameter division model fitted to the near lines straightens it to 0.16 px and cuts the far-sideline error from 5.95 to 1.96 cm. Its centre is assumed to be the frame centre, and no calibration of this camera exists to check that. The lessons work in raw pixels; the corrected row above is the size of what they leave on the table. The distortion lesson covers the model.
- Paint was found as a ridge, and that choice moves the numbers. The ridge comes from a white top-hat, a morphological filter that unit 2.2 will cover. A brightness threshold alone also admits the pale grey of the non-volley zone. With it, the far baseline error is 81.3 cm instead of 38.4, because the grey sits on one side of the kitchen line and drags its fit.
- The outdoor clip reproduces to the frame, not to the byte.
yt-dlp --download-sectionsre-encodes the cut with the local encoder, so the section file’s hash differs between machines. The outdoor numbers are tied to frame indices within the section, not to a checksum. - The seed does not leak, and that was checked. The lines are found near four corner positions typed in by eye. Moving those by up to 5 px in 20 random trials moves no fitted corner by more than 0.58 px.
What this means for your pipeline
- Anything flat seen at an angle needs the full homography. An affine map, the usual shortcut, missed the fourth corner by 3.50 m here. It is close enough only when the camera looks nearly straight at the surface.
- More than four points helps, not everywhere. A least-squares fit on six points cut the centre-mark errors (NKC 5.63 → 3.18 cm) and made the far right sideline worse (5.95 → 8.53 cm). Check on points the fit never saw.
- Expect the error to grow with distance. One pixel spans 0.6 cm of court at the near baseline and 8.1 cm at the far one, so the far baseline’s 38.4 cm is under 5 px.
- Correct the lens before measuring far away. A one-parameter distortion fit took the far sideline from 5.95 to 1.96 cm.
- Never trust one hand-typed pair. A single corner given the wrong court position, among six, put the far baseline 17.6 m off; that is the job of step 7.
- What this does not tell you: where anything off the plane is. A player’s head or the top of the net post pushed through the map lands on the court far behind where it is.
Your turn: other maps
For each case, count the unknown numbers, the point pairs needed to fix them, and say what one fixed homography of the court does.
- A similarity (rotate, scale and shift, no shear): how many numbers, how many pairs? And an affine map? And a homography?
- The position and angle of a camera in 3-D, when its focal length is known.
- One fixed court homography applied to the top of the net post, to a player’s head, and to the next frame after the camera pans.
Answers
- A similarity has 4 numbers (a scale, an angle, a shift in x and in y), and each point pair gives two equations, so 2 pairs fix it. Affine: 6 numbers, 3 pairs. A homography: 8 numbers, 4 pairs, no three of them on one line.
- 6 numbers: three for the rotation and three for the position. Each point with a known 3-D position gives two equations, so three points fix it, with a few discrete answers to choose between; a fourth picks the right one. That is PnP, the 3-D version of this fit.
- The net post’s top and the head are not on the court’s plane, so the map sends each to the floor point behind it along the camera’s ray: both land well beyond where they stand. After a pan the whole picture moves, so the old matrix is wrong for every pixel; a camera that only turns is related to its previous view by a new homography, which is how panoramas are joined.
Where this lands
The measured system this unit points at does not exist as a post yet: a ball and player tracker that puts every bounce on the court in metres runs on this homography, and the article on it is pending. Until then the nearest thing on the site is structure from motion, which is what you need when the scene is not a plane and one 3×3 no longer describes it.
How these numbers were made
| Parameter | Value |
|---|---|
| CPU | 12th Gen Intel Core i7-12700H, 20 threads |
| GPU | none used; everything runs on the CPU (the machine has an RTX 3060 Laptop GPU) |
| RAM / OS | 31 GB · Ubuntu 22.04.5 LTS, kernel 6.8.0-138 |
| Key versions | Python 3.12.9, OpenCV 5.0.0 [10], NumPy 2.5.2 |
| Data | YouTube T5rmWjvt8Os by pickleball4you, CC BY 3.0 [9]: frame 45000 (shown) and the per-pixel median of 31 frames, 44100 to 45900 every 60 (measured) |
| In the wild | YouTube K0qrASvix3Y by pickleball4you, CC BY 3.0, 450–520 s, 31 frames every 60, median (lessons 1–3 and 4.1-L1); BarcelonaHarbour1.jpg and BarcelonaHarbour2.jpg by Pap3rinik, Wikimedia Commons, public domain, resized to 1600 px (lesson 5). All registered in CondadosAI/cv-assets with licence and sha256, downloaded, never redistributed |
| Court model | USA Pickleball 2026 rulebook, Rule 3.A [8]; lines at their centres, 2.54 cm inside each nominal dimension |
| Commands | uv run align-download, then uv run align-experiments and uv run align-figures (which also draws the hub’s pipeline panels) |
| Runs | deterministic, except the DLT noise study: 1,000 draws of σ = 1 px from seed 20260926 |
| Excluded | no timing is reported in this unit; every number is a distance, a count or a ratio |
Every number in the posts is a key in output/alignment_numbers.json or the printed
output of a cell on the page, which the unit notebook reproduces. The frame and
the median plate are served from this site as lossless WebP, so the notebook measures
the same pixels the repository does. The 31 frames are served at 960 px for the
notebook’s median demonstration; align-download --from-youtube fetches them at full
resolution.
Why the median. The camera never moves in that minute, and the players do. In frame 45000 the near player’s white shirt stands on the left sideline, and a detector looking for white paint takes it for paint. The median of 31 frames is the court with nobody on it; the six near-court corners found on it and on frame 45000 agree to within 1.3 px.
Further reading
- Go deeper: Hartley & Zisserman, ch. 4 “Estimation – 2D Projective Transformations” [1], for the DLT, the cost functions it approximates and the normalisation argument in full.
- The practitioner’s map: Szeliski, ch. 8 “Image Alignment and Stitching” [3], and his earlier tutorial of the same name [4], for how panorama software strings these steps together.
- Related on CondadosAI: homogeneous coordinates is the prerequisite · PnP is the 3-D version of the same fit.
References
[1] Hartley, R., & Zisserman, A. (2004). Multiple View Geometry in Computer Vision (2nd ed.), ch. 4 “Estimation – 2D Projective Transformations”, §4.1 “The Direct Linear Transformation (DLT) algorithm”, p. 88, and §4.4 “Transformation invariance and normalization”, p. 104. Cambridge University Press.
[2] Hartley, R., & Zisserman, A. (2004). Multiple View Geometry in Computer Vision (2nd ed.), §2.4 “A hierarchy of transformations”, p. 37. Cambridge University Press.
[3] Szeliski, R. (2022). Computer Vision: Algorithms and Applications (2nd ed.), ch. 8 “Image Alignment and Stitching”, §8.1 “Pairwise alignment” and §8.4 “Compositing”. Springer. Free PDF
[4] Szeliski, R. (2006). Image Alignment and Stitching: A Tutorial. Foundations and Trends in Computer Graphics and Vision, 2(1), 1–104. doi:10.1561/0600000009
[5] Fischler, M. A., & Bolles, R. C. (1981). Random Sample Consensus: A Paradigm for Model Fitting with Applications to Image Analysis and Automated Cartography. Communications of the ACM, 24(6), 381–395. doi:10.1145/358669.358692
[6] Hartley, R. I. (1997). In Defense of the Eight-Point Algorithm. IEEE Transactions on Pattern Analysis and Machine Intelligence, 19(6), 580–593. doi:10.1109/34.601246
[7] Gonzalez, R. C., & Woods, R. E. (2018). Digital Image Processing (4th ed.), §2.6 “Introduction to the Basic Mathematical Tools Used in Digital Image Processing”, Geometric Transformations, p. 84, and Image Registration, p. 88. Pearson.
[8] USA Pickleball (2026). Official Rulebook, Rule 3.A “Court Specifications” (3.A.1, 3.A.2, 3.A.4.c, 3.A.4.e). usapickleball.org
[9] pickleball4you (2026). 2026.07.25 WD Open - Sabrina Lam + Grace Thomas vs Lingzhe Xu + Margit Aardmaa (Gold Medal match). YouTube, CC BY 3.0. youtube.com/watch?v=T5rmWjvt8Os
[10] OpenCV Documentation (5.0). Basic concepts of the homography explained with code. docs.opencv.org/5.0
[11] Zhang, Z. (2000). A Flexible New Technique for Camera Calibration. IEEE Transactions on Pattern Analysis and Machine Intelligence, 22(11), 1330–1334, §2.2 “Homography between the model plane and its image” in the technical report MSR-TR-98-71. doi:10.1109/34.888718
[12] Brown, M., & Lowe, D. G. (2007). Automatic Panoramic Image Stitching using Invariant Features. International Journal of Computer Vision, 74(1), 59–73. doi:10.1007/s11263-006-0002-3