System designHow-to

Bird's-eye view from rotation and translation: build the homography

Turn a camera rotation matrix and translation into a bird's-eye warp: compose H = K·[r1 r2 t], build the OpenCV matrix, and verify with a reprojection test.

LumaSpec Vision9 min read Share on LinkedIn

On this page 9 sections
  1. 01From pose to homography in one formula
  2. 02What you need before you build
  3. 03Build the warp matrix in five steps
  4. 04Worked example: level camera, 900 mm above the floor
  5. 05Verify the map before you trust it
  6. 06When the output looks wrong
  7. 07Set the output scale from the source pixels
  8. 08Camera and lens choices that keep the warp true
  9. 09Questions

You have a rotation matrix R (3×3) and a translation t (3×1) for the camera relative to a flat target, and you want the same bird's-eye map that cv2.getPerspectiveTransform gives you from four point pairs — without collecting points. For any plane you can compute the homography directly: H = K·[r1 r2 t], where K is the camera's 3×3 intrinsic matrix and r1, r2 are the first two columns of R. This guide composes H into the OpenCV warp matrix, works the arithmetic on a level camera 900 mm above the floor, and shows the checks that catch the two classic mistakes: a pose that points the wrong way and units that disagree. It is for anyone wiring a pose from a solver or another team into a top-down inspection map.

From pose to homography in one formula

A plane lets you skip correspondences entirely. Take the target frame so the target lies at Z = 0. A plane point P = (X, Y, 0) becomes, in camera coordinates, R·P + t = r1·X + r2·Y + t, with r1 and r2 the first two columns of R. The intrinsics project it: K·(r1·X + r2·Y + t) = K·[r1 r2 t]·(X, Y, 1)^T. So the 3×3 that maps plane millimetres to image pixels is exactly H = K·[r1 r2 t] — the same matrix the general homography form writes as R − t·n^T/d for a plane with normal n at distance d.

H = K · [ r1 r2 t ] u = (H00·X + H01·Y + H02) / (H20·X + H21·Y + H22)

Three properties matter in practice. The coordinates X and Y carry the units of t, because H only consumes what you feed it. H is defined up to scale, so dividing by H22 is cosmetic but keeps the numbers readable. And the bottom-row division is what removes perspective: tilt the camera and H20, H21 become non-zero, which is exactly the term the bird's-eye map cancels.

What you need before you build

Build the warp matrix in five steps

  1. Assemble K as a float64 3×3: rows [[fx, 0, cx], [0, fy, cy], [0, 0, 1]].
  2. Form H = K @ np.hstack([R[:, :2], t]) and normalise H /= H[2, 2].
  3. Choose the bird's-eye window in plane coordinates: X and Y ranges in millimetres, an output scale s in millimetres per output pixel, and the offset (x0, y0) where the plane origin lands in the output.
  4. Compose M = H @ S, with S the 3×3 that carries an output pixel to plane millimetres: [[s, 0, −s·x0], [0, s, −s·y0], [0, 0, 1]].
  5. Call cv2.warpPerspective(img, M, (width_out, height_out), flags=cv2.INTER_LINEAR). The documented convention resolves each destination pixel through M, so M must map output pixels to source pixels — which H @ S already does.
import numpy as np
import cv2

# Illustrative inputs: replace with your calibration and pose.
K = np.array([[3000.0, 0.0, 2000.0],          # fx, 0, cx in pixels
              [0.0, 3000.0, 1500.0],          # 0, fy, cy
              [0.0, 0.0, 1.0]])               # 3x3 float64
R = np.eye(3)                                 # camera level, 3x3
t = np.array([[-150.0], [-100.0], [900.0]])   # object->camera pose, mm, 3x1
img = source_frame                            # your captured frame

H = K @ np.hstack([R[:, :2], t])              # plane (X, Y, 1) -> image pixels
H = H / H[2, 2]

s = 1.0                                       # mm per output pixel
x0, y0 = 600.0, 450.0                         # plane origin at output (600, 450)
S = np.array([[s, 0.0, -x0],
              [0.0, s, -y0],
              [0.0, 0.0, 1.0]])
M = H @ S                                     # output pixel -> source pixel

bev = cv2.warpPerspective(img, M, (1200, 900), flags=cv2.INTER_LINEAR)

If the call rejects your arrays, the usual cause is dtype or shape; the homography warp array type error fix walks through that. Mapping pixel coordinates through a homography shows how a single (u, v) pair travels the same path by hand.

Worked example: level camera, 900 mm above the floor

Use the illustrative K above on a 4000 × 3000 image, camera level with R = identity, and t = (−150, −100, 900) mm: 150 mm to the −X side, 100 mm to −Y, 900 mm up. Multiply through:

  • K·r1 = (3000, 0, 0), K·r2 = (0, 3000, 0)
  • K·t = (3000·(−150) + 2000·900, 3000·(−100) + 1500·900, 900) = (1 350 000, 1 050 000, 900)

So H = [[3000, 0, 1 350 000], [0, 3000, 1 050 000], [0, 0, 900]], and dividing by H22 = 900 gives [[3.3333, 0, 1500], [0, 3.3333, 1166.67], [0, 0, 1]]. The scale on the plane is 3000/900 = 3.3333 px/mm, so the 4000-pixel width sees 4000/3.3333 = 1200 mm and the 3000-pixel height sees 900 mm.

Pick the window X ∈ [−600, 600], Y ∈ [−450, 450] mm at s = 1 mm/px: a 1200 × 900 output with the plane origin at pixel (600, 450). Then

M = H @ S = [[3.3333, 0, 1500 − 2000], [0, 3.3333, 1166.67 − 1500], [0, 0, 1]] = [[3.3333, 0, −500], [0, 3.3333, −333.33], [0, 0, 1]].

Hand-check the centre: output pixel (600, 450) maps to source (3.3333·600 − 500, 3.3333·450 − 333.33) = (1500, 1166.67), which is exactly where u = 3.3333·X + 1500 and v = 3.3333·Y + 1166.67 put the plane origin. The bottom-left output pixel (0, 0) maps to (−500, −333.33) — off the sensor. The camera sits 150 mm off-centre, so the strip X < −450 mm is simply not in view; shift the window to X ∈ [−450, 750] to use every source pixel, or accept a black 150-pixel border.

Tilt the same camera 30° about the X axis and nothing else changes structurally: r2 picks up sin(30°)/900 = 0.000556 in the bottom row, so λ = 1 + 0.000556·Y, and the division now does the foreshortening removal for you.

A 12 MP USB3 camera with a 4000 × 3000 sensor is the class of hardware this example assumes:

Area scan cameras12 MP USB3 area scan camera, IMX226, 1/1.7" rolling shutter, 30 fps, 4000 × 3000 resolution (LS-CMR-0166)LS-CMR-0166
Sensor format
1/1.7"
Interface
USB3
Resolution
12 MP
Shutter
Rolling
$560.00View partBuild a system with it

Verify the map before you trust it

Three checks, cheapest first.

Reprojection. Pick a plane point with known coordinates, say (300, 200) mm. With the H above: u = 3.3333·300 + 1500 = 2500, v = 3.3333·200 + 1166.67 = 1833.33. Detect that corner in the source image; agreement within about a pixel says K, R and t agree. With a tilted pose, use the full division: u = (H00·X + H01·Y + H02)/(H20·X + H21·Y + H22).

Cross-check against points, once. Run cv2.findHomography on the corners your detector finds and compare element-wise with the pose-built H. Relative agreement around 0.1% means the pose direction and units are right.

Measure in the output. Two plane points 200 mm apart must land 200 px apart in a 1 mm/px map, wherever they sit in the window.

If you still need R and t, one image with four known ground points provides them — the ground-plane pose from one image using four known points method runs the derivation in the opposite direction. For maps that feed live tracking rather than a static warp, the same H drives mapping tracking points onto a ground plane.

When the output looks wrong

  • Black output or a far-off shift: the pose points the wrong way — apply R^T and −R^T·t — or the units disagree. Metres where you assumed millimetres moves the window by 1000×.
  • Uniformly too big or too small: fx or the height in t is off by one factor. The origin-projection test finds it in one line: the plane origin should land near the principal point.
  • Straight edges bow near the frame corners: uncorrected distortion. Undistort with the calibration coefficients before warping.
  • Moving parts smear: a rolling shutter exposes each row at a different instant, so one H per frame cannot hold. Use a global-shutter camera or a strobed exposure.
  • Output sharper than the source allows: the plane carries 3.3333 px/mm in the example, so an output scale finer than 1/3.3333 ≈ 0.30 mm/px invents detail.

Set the output scale from the source pixels

The source sets the finest useful scale: px/mm on the plane = fx / height = 3000/900 = 3.3333 px/mm. So s = 0.30 mm/px uses full sensor detail and s = 1 mm/px downsamples 3.3× for a cleaner map. Window divided by scale gives the output size: 1200 mm at 0.30 mm/px needs 4000 px, exactly what the sensor delivers across. The camera resolution calculator runs the same trade the other way, from window size and feature size to the pixels you need:

Camera resolution for the smallest feature
Units
Pixels needed
–
Sensor size
– MP
Smallest sensor that fits
–
Pixel on the part
– mm
Pixels across the feature, that sensor
–

Pixels needed = field / feature × pixels per feature on each axis (field incl. margin). The lens must resolve the pixels too: Nyquist = 1000 / (2 × pixel µm) lp/mm.

Find cameras with enough pixels Open the full calculator

Camera and lens choices that keep the warp true

H assumes a pinhole, so distortion is the one optical term it ignores. Pick a lens that prints its distortion and resolves the sensor: a plane width budget of sensor width × height ÷ focal length tells you the focal length for your window before you order. The 16 mm, 1.1-inch-format, 20 MP C-mount lens below is specified at F2.8-22 with under 0.3% distortion:

Machine vision lenses16 mm, 1.1", 20 MP, C-mount machine vision lens, F2.8-22, <0.3% distortion (LS-FFL-0567)LS-FFL-0567
Type
Machine vision fixed
Sensor format
1.1"
Mount
C-mount
Resolution
16-25 MP
$679.00View partBuild a system with it

On a 12 MP, 1/1.7" sensor that leaves margin in both circle and resolving power, and its fixed focus holds the calibration you throw at it. Browse the area scan cameras page for the sensor, the machine vision lenses finder for the optics, or start the camera configurator from your window size and mounting height. The lens finder filters by focal length and format, expert support comes with every order for the calibration numbers, and the systems topic page collects the neighbouring guides. If a station needs a second opinion before you cut metal, the contact page reaches the applications team.

Questions

Do I still need a checkerboard if I already have the pose?

Only once, at calibration: the intrinsics K and the distortion coefficients come from a one-time board calibration. After that the pose alone defines H. Keep a target with known corners mounted nearby so you can run the reprojection check after any bump or lens change. If you cannot calibrate at all, fall back to point correspondences and cv2.findHomography — the pose route needs K.

What happens if the translation is in metres instead of millimetres?

The warp still runs, but the plane coordinates that H consumes carry t's units. A translation in metres with a scale set for millimetres moves the output window a thousandfold — usually a black image. Set s and the offsets in the same unit as t, then confirm by projecting the plane origin: it must land near the principal point (cx, cy) of the image.

Why is my warp matrix affine, with bottom row 0 0 1?

Because the camera axis is perpendicular to the plane. With a level camera the perspective row of H is (0, 0, 1) and the warp reduces to a scale and shift. Tilt the camera and H20, H21 take non-zero values; the bottom-row division then does the foreshortening removal. Both matrices are valid inputs to cv2.warpPerspective.

Can one homography serve a moving conveyor?

Yes, if camera and plane stay rigid: a fixed overhead camera over a flat belt needs H computed once, and parts simply translate inside the map. Recompute H per pose when the camera or the plane moves. Prefer a global-shutter camera there; a rolling shutter builds each row at a different instant, so a single warp smears fast parts.

How accurate is a pose-built bird's-eye view?

It inherits the calibration. With a careful intrinsics calibration, detected corners should reproject within roughly half a pixel, and agreement between the pose-built and point-built homography around 0.1% is healthy. If your check exceeds two to three pixels, suspect the pose direction, the units, or a calibration done at a different working distance, in that order.