System designExplainer

Find camera distance to a tape line from its pixel width

Turn a known tape width and its width in pixels into camera distance: the one-photograph calibration, the formula, a worked example, tilt and the error budget.

LumaSpec Vision10 min read Share on LinkedIn

On this page 9 sections
  1. 01One width, one distance: the similar-triangles relation
  2. 02Calibrate the constant with one photograph
  3. 03Worked example: 50 mm of tape from 1 m to 2 m
  4. 04Choosing the focal length from the other end
  5. 05What tilt, distortion and focus do to the number
  6. 06The error budget, computed
  7. 07When a single camera is the wrong tool
  8. 08The same measurement on machine-vision hardware
  9. 09Questions

A single camera can measure how far it sits from a marked line, provided you know one physical dimension of that line: its width. A tape twice as far away looks half as wide, and that ratio is all the distance sensing a line-following vehicle, a docking station or a web guide needs. You calibrate one constant — the focal length expressed in pixels — from a single photograph, then compute distance every frame with one division. This page gives you the relation, the calibration shot, a worked example with the arithmetic written out, the tilt and distortion terms that move the answer, an error budget, and the lenses and area scan cameras to build it on.

One width, one distance: the similar-triangles relation

A camera sees angles, not metres. A width W seen from distance D subtends an angle, and the lens maps that angle onto the sensor as a count of pixels. For a rectilinear lens the mapping is linear, and the proportionality constant is the focal length measured on the pixel grid, written f_px. It is one number for one camera-plus-lens at one zoom and focus setting, and it is the same constant that fixes your angle of view.

Three forms of one relation cover every use:

width_px = f_px × W / D (how wide the line looks) D = W × f_px / width_px (the distance you want) f_px = width_px × D / W (the calibration shot)

Any consistent length unit works — metres for both W and D, or millimetres for both — because the units cancel inside each equation; width_px and f_px are always pixels. The same bookkeeping gives millimetres per pixel at a fixed stand-off, which is the object-space pixel size calculation behind measurement at a set distance; sorting coins by size from pixels is the identical arithmetic. If the application needs pixel measurements in real units more broadly, calculating pixel distance in real units is the same similar-triangles workflow.

How sensor width, working distance and field of view set the focal length Rays from the edges of the sensor pass through the lens and spread to the edges of the field of view. The ratio of sensor width to field of view is the magnification m.CameraField of view (FOV)Working distance (WD)≈ fsensor width slensm = s / FOVf = WD × m / (1 + m)
How sensor width, working distance and field of view set the focal length. Rays from the edges of the sensor pass through the lens and spread to the edges of the field of view. The ratio of sensor width to field of view is the magnification m.

Typical uses: a model car or AGV steering off a centre tape, docking to a taped floor mark, and web-edge guiding, where the controller consumes one width reading per frame.

Calibrate the constant with one photograph

You need a tape of known width, one measured distance and one image. Lay the tape square to the camera — width direction perpendicular to the viewing direction — at a distance taken from a tape measure or a marked floor position. Shoot, threshold whatever separates the tape from the floor, and count the pixels across; a selection rectangle in an image editor is accurate enough for the first calibration. Then apply the third form: f_px = width_px × D / W.

The photograph also freezes the zoom and focus setting, and f_px belongs to that setting: change the zoom and it is void. Lock the focus the way you would before any camera calibration and leave it there. When you also need undistorted measurements across the whole frame, a full intrinsic calibration from a checkerboard target returns f_px together with the distortion coefficients — calibration for length measurement from image markers shows that route.

Worked example: 50 mm of tape from 1 m to 2 m

Calibration shot: a tape 50 mm wide, placed 1.00 m from the lens, spans 250 px.

f_px = 250 px × 1.00 m / 0.050 m = 5,000 px Live frame, tape reads 125 px: D = 0.050 m × 5,000 px / 125 px = 2.00 m Live frame, tape reads 400 px: D = 0.050 m × 5,000 px / 400 px = 0.625 m

Halve the pixel width and the distance doubles. The relation is exact for an ideal pinhole and lands inside the error budget below on any rectilinear lens. On a vehicle this is the per-frame number the steering loop consumes: the cross-track distance to the tape at the row being measured.

Choosing the focal length from the other end

Work the equation backwards before buying anything. Decide the smallest pixel width the tape must show at the farthest distance that matters — the error budget below explains why that decides your accuracy — then f_px = width_px × D / W, and the millimetre focal length follows from the pixel pitch: f_mm = f_px × pitch.

Example: a 50 mm tape must read at least 300 px at 1.20 m, so f_px = 300 × 1.20 / 0.050 = 7,200 px. Take a sensor 1920 px wide with 3.45 µm pixels — an illustrative pitch, swap in your own sensor's numbers — and the sensor is 1920 × 3.45 µm = 6.6 mm wide, so f_mm = 7,200 × 0.00345 mm = 24.8 mm: a 25 mm lens is the nearest standard pick. The calculator below does the same job from field of view and working distance, and the focal-length selection guide walks the wider trade.

Lens focal length, field of view and working distance
Units
Solve for
Focal length
– mm
Field of view
– mm
Working distance
– mm
Magnification
– x
Angle of view
– °
Pixel on the part
– mm

Thin-lens model: m = sensor width / field of view, f = WD × m / (1 + m). Accurate to a few percent above about 150 mm; check the lens's minimum object distance.

Find lenses with this focal length Open the full calculator

On that example sensor, the same 50 mm tape at 1.20 m reads about 97 px wide through an 8 mm lens, 302 px through 25 mm and 423 px through 35 mm. Longer focal length means more pixels on the tape and a narrower field of view — the lens finder shortlists by focal length and sensor format once the equation has spoken.

What tilt, distortion and focus do to the number

Square-on is the assumption. Yaw the tape by an angle θ and its apparent width shrinks by cos θ, so the computed distance reads high by 1/cos θ: +1.5% at 10°, +6% at 20°, +16% at 30°. If the line fit reports the yaw, multiply the computed distance by cos θ to correct it.

A lane tape running ahead of a level camera still works, row by row. On flat ground a horizontal image row cuts the ground at one range, and the tape's width across that row converts to that range with the same formula; rows lower in the image are closer. One row gives one distance; the full run — curvature metres ahead — needs a ground-plane pose calibration instead.

Lens distortion bends the pinhole model: f_px holds at the image centre and drifts by up to the distortion figure toward the edges, so keep the tape inside the central two-thirds of the frame or choose a lens with a printed distortion spec. Refocusing moves the lens groups and shifts f_px with them — the calibration shot is one focus setting, so keep it there. A rolling shutter shears rows while a vehicle moves, corrupting row-by-row widths, so moving vehicles want a global shutter.

The error budget, computed

Distance is inversely proportional to width_px, so the relative distance error equals the relative error of the pixel measurement. Count the tape to ±1 px: on a 250 px reading that is ±0.4%, on 100 px ±1%, on 40 px ±2.5%. The yaw term and the distortion figure add on top.

Working budget: tape spanning 150 px or more, yaw within 5°, inside the central two-thirds of a lens with distortion under 0.5%. The pixel term is 1/150 ≈ 0.7%, the yaw term 1/cos 5° − 1 ≈ 0.4%, distortion 0.5%; the root-sum-square is about 1%, and segmentation jitter brings the working figure to ±2%. At 300 px the pixel term drops to 0.33% and about ±1% is realistic. When more accuracy is needed, more pixels on the tape — longer focal length or a higher-resolution sensor — buys more than threshold tuning does.

When a single camera is the wrong tool

The method needs a known width, cleanly visible. It has no answer for an object whose size is unknown — a pixel width needs a real dimension to scale against — and depth from stereo or time-of-flight supplies distance without one, at the cost of a second sensor or an active illuminator plus its own pixel-Z-to-camera-distance conversion. The second failure is glare: a glossy tape on a shiny floor can wash out to white, and a blue streak across the frame is usually a reflection rather than the tape. That too is normally fixed with lighting before software — pick the LED colour that maximises tape-versus-floor contrast.

The same measurement on machine-vision hardware

Nothing here needs a webcam. On industrial hardware the method is the same three lines of arithmetic; what you gain is a fixed C-mount focus, a global shutter for the moving case and a lens chosen for the stand-off. Hue-based segmentation wants a colour sensor, and the area scan camera finder filters by shutter, interface and colour.

A 2/3-inch-format lens covers a 1/1.7-inch sensor with margin, and a 1.1-inch-format lens covers a 1-inch sensor.

The MV-CU020-90GC is a 2.5 MP colour GigE camera with a global shutter and C-mount on a 1/1.7-inch sensor — the direct stand-in for a tape-following vehicle camera.

Area scan camerasHikrobot MV-CU020-90GC 2.5 MP Area Scan Camera, GigE, GMAX4002, ColorMV-CU020-90GC
Sensor format
1/1.7"
Lens mount
C-mount
Interface
GigE
Resolution
Up to 3 MP
$309.00View partBuild a system with it

Close quarters want a wide field; standoff wants focal length. For short stand-off, the LS-FFL-1582 is an 8 mm FA lens for 2/3-inch sensors in C-mount with a listed 57.6° field of view; from further back, the LS-FFL-0679 is a 35 mm, 2/3-inch, 6 MP C-mount lens.

Machine vision lensesFA lens, 8 mm, 2/3", C-mount, FOV 57.6° (LS-FFL-1582)LS-FFL-1582
Sensor format
2/3"
Mount
C-mount
$309.00View part
Machine vision lenses35 mm, 2/3", 6 MP, C-mount machine vision lens (LS-FFL-0679)LS-FFL-0679
Type
Machine vision fixed
Sensor format
2/3"
$219.00View part

A stationary measurement point inverts the priority: accuracy first, vehicle dynamics not applicable. The MV-CS200-10UM is a 20 MP, 1-inch, mono USB3 camera in C-mount with a rolling shutter — stationary, the rolling shutter costs nothing. A mono sensor reads brightness only, so the tape-versus-floor contrast must come from the light rather than hue. The LS-FFL-0567 is a 16 mm, 1.1-inch, 20 MP, C-mount lens with an F2.8-22 iris and <0.3% distortion, which keeps the pixel measurement honest toward the frame edges.

Area scan camerasHikrobot MV-CS200-10UM 20 MP Area Scan Camera, USB3.0, IMX183, 2nd Gen., MonoMV-CS200-10UM
Sensor format
1"
Lens mount
C-mount
$759.00View part
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"
$679.00View part

Checks before the first live reading:

  • f_px from three calibration distances agrees within about 1%.
  • One live reading at a measured 2.00 m matches a tape measure within the budget.
  • Zoom and focus untouched since the calibration shot.
  • The tape stays inside the central two-thirds of the frame at the farthest working distance.
  • The segmentation threshold survives a lighting change: room lights off, shadows crossing.

Sketch the stand-off, run the two equations, and the hardware shortlist follows: the lens configurator starts from the focal length the equation asks for, and the contact page reaches the applications team with the sketch. More single-camera geometry — pose from known points, calibration targets, pixel-size arithmetic — sits on the systems topic page.

Questions

How far away can the tape be before this stops working?

Arithmetically, never — width_px falls as 1/D and the formula keeps dividing. Practically, keep the tape at 50 px or wider in the frame: on the worked example's 5,000 px constant that is 5.0 m, where a ±1 px segmentation error already costs ±2%. To reach farther, raise f_px — a longer focal length, a sensor with more pixels, or both — or widen the tape; quadrupling f_px quadruples the reach at the same 50 px floor.

Does the tape have to be exactly perpendicular to the camera?

Small yaw is affordable: at 10° the distance reads about 1.5% high, at 30° about 16% high. Two practical fixes: while approaching, keep frames where the tape reads widest — the widest reading is the square reading — or, if the line fit reports the yaw angle, multiply the computed distance by its cosine to recover the true value.

Can I use the tape's length instead of its width?

Only when the length lies square across the view, like a start-line stripe. A tape that runs ahead of the camera presents no single length at one distance — every image row cuts it at a different range — while its cross-track width is measurable in any single row. Width is the robust input; length requires a ground-plane calibration first.

How often does the pixel focal length need recalibrating?

Once per mechanical configuration. Zoom is absolute: any zoom change voids f_px outright. Focus-setting changes shift it slightly, so lock the ring; aperture does not move it by anything that matters at these tolerances. With lens, focus and zoom untouched, f_px is a fixed geometric constant — no periodic recalibration — though repeating the three-distance check after a lens swap or a knock is worthwhile insurance.

What makes blue tape easy or hard to segment?

Colour helps: blue tape keeps its hue while brightness swings with the lighting, so thresholding the hue channel survives shadows that defeat a grey threshold. A mono sensor sees brightness only and depends on the light colour for separation. Watch for specular glare flattening the tape on shiny floors, and avoid exposure that clips the blue channel, which destroys the hue information.