A detector can locate an object without knowing how far away it is. Turning its image size into distance requires additional information: a known physical dimension, a calibrated camera model, or another constraint that removes ambiguity. This distinction matters when you want to display distance beside a detection or use it for inspection decisions.
For a fixed camera viewing consistently sized, consistently oriented parts, a geometric estimate is often the simplest starting point. You can calibrate it without changing a detector’s training format. The following method explains the assumptions, shows the arithmetic, and identifies when a single image cannot provide a dependable answer.
Decide whether apparent size is enough
Object distance estimation from apparent size works when you know which physical dimension produced the measured pixel dimension. A standard-width package facing the camera is a reasonable candidate. An arbitrary object belonging to a broad category is not: different physical sizes can create identical images at different distances.
Use this approach when:
- The measured object dimension is known and has a controlled tolerance.
- The same physical edges remain visible across the operating range.
- Object orientation is constrained or measured separately.
- Focus, zoom, image scaling and camera mounting remain fixed.
- The required accuracy leaves room for pixel measurement and calibration errors.
The geometry is the inverse of measuring object size from a camera image. There, distance or scale is known and physical size is calculated. Here, physical size is known and distance is calculated.
| Available information | Suitable approach | Main limitation |
|---|---|---|
| Known width and controlled orientation | Apparent-size geometry | Size tolerance and edge localization |
| Known planar target with visible corners | Calibrated planar pose estimation | Target geometry and corner accuracy |
| Object resting on a calibrated plane | Image-to-plane mapping | Object height and plane departures |
| Unknown size and unconstrained orientation | Stereo or depth sensing | Depth validity, calibration and scene conditions |
| Representative distance-labeled images | Learned distance regression | Dataset coverage and domain changes |
For floor-supported objects, ground-plane pose from known points may be more appropriate than assuming a constant object width.
Understand the projection equation
For an ideal pinhole camera, a known width parallel to the image plane projects according to the following relationship. The width’s endpoints must be at the same camera-axis depth.
Keep physical length units consistent. If W is in millimeters, Z will also be in millimeters. The focal length in pixels is not the lens focal length printed in millimeters; it comes from camera calibration or a suitable conversion using sensor geometry.
This equation returns axial depth, not necessarily straight-line distance from the camera to an off-center object. In camera coordinates, straight-line range is calculated separately.
For example, an object at Z = 1.6 m and X = 1.2 m, with Y = 0 m, has range R = √(1.6² + 1.2²) = 2.0 m. Label the displayed quantity clearly. The distinction is explained further in depth value versus true distance.
Calibrate a fixed camera and measurement pipeline
You do not always need a complete intrinsic calibration for a narrow, controlled application. A known-size reference at a known depth can establish an empirical scale constant. However, full calibration becomes more useful when distortion, off-axis positions or object pose matter.
- Choose a physical feature. Use two repeatable edges or fiducial points whose separation is known. Avoid shadows, flexible outlines and dimensions hidden by packaging.
- Fix the imaging setup. Set the working focus, lock any adjustable zoom, and establish the final image resolution and processing path.
- Define the distance origin. Use the camera-coordinate origin, or account for a separately calibrated offset from a mechanical datum. Do not silently treat the front housing as the projection center.
- Capture a reference measurement. Place the feature at a known axial depth and measure its pixel separation using the same method intended for production.
- Calculate the scale constant. Multiply reference depth by reference pixel width.
- Validate at other depths and image positions. A calibration that matches its own reference image has not yet demonstrated useful accuracy.
Use several reference positions to check whether a single K adequately describes the operating range. Systematic departures can indicate distortion, pose changes, inconsistent edge definitions or a distance-origin error.
If you use a calibration target, its dimensions, flatness and coverage affect the calibration. The calibration target coverage guide explains why a small target near the image center may leave the edges poorly characterized.
Work through a numerical example
Assume a rigid target has a known width of 200 mm and faces the camera. At an axial reference depth of 1,000 mm, its corresponding edges are 400 pixels apart.
A later image measures the same feature at 250 pixels wide.
Now suppose width measurement uncertainty is approximately ±3 pixels. The first-order contribution to depth uncertainty is:
That is only the pixel measurement contribution. It excludes uncertainty in reference distance, physical width, pose and the camera model.
At 2,400 mm, the projected width becomes approximately 400,000 / 2,400 = 167 pixels. The same ±3-pixel uncertainty contributes about 1.8%, or 43 mm. Distance performance deteriorates as the feature occupies fewer pixels.
For sampling planning, suppose the far-range horizontal field of view is 1,200 mm and the 200 mm feature should occupy at least 300 pixels. The required horizontal sampling is approximately 1,200 / 200 × 300 = 1,800 pixels. Use the resolution calculator to explore this field-of-view and feature-sampling tradeoff.
The target pixel count is a sampling requirement, not a complete accuracy guarantee. Optical blur and unstable edge detection can still dominate.
Account for size, pose and image-processing errors
Physical size tolerance transfers directly into the distance estimate. If the algorithm assumes a width of 200 mm but the actual width is 190 mm, it overestimates depth by approximately 200 / 190 − 1 = 5.3%, even with perfect image measurements.
Rotation creates another ambiguity. For a relatively small target compared with its distance, yaw foreshortening can be approximated using a cosine. At 30° yaw, apparent width is roughly 0.866 times the front-facing width. Ignoring that rotation can overestimate depth by about 1 / 0.866 − 1 = 15.5%. Close targets require the full perspective geometry rather than this approximation.
Detector rectangles introduce additional variation. Their boundaries may follow visible texture, include background, clip an occluded object, or change with detection confidence. A stable detection does not prove that its box width represents a stable physical dimension.
Use detection to select the region, then measure a defined feature inside it when possible. The guide to edge position accuracy explains why sampling alone does not determine measurement quality.
Image transformations also need consistent handling:
- Resizing: multiplying image dimensions by 0.5 also multiplies measured widths and focal length in pixels by 0.5.
- Cropping: a pure crop preserves pixel separations but changes coordinate origins and possibly visibility.
- Padding: padding adds borders without enlarging the object, but detector coordinates must be mapped back correctly.
- Undistortion: use geometry calibrated for the corrected image, including any subsequent crop or resize.
Keep geometric distance separate from detector training
Adding a distance field to an annotation file does not automatically make an existing detector learn distance. The data loader, prediction outputs, training loss and inference code must all understand the additional quantity.
A cleaner baseline is often to leave detection unchanged. Detect the object, identify the appropriate physical feature or size class, measure its image dimension, and calculate distance afterward. This makes the assumptions visible and allows geometry to be checked independently of classification performance.
Learned distance regression is a different engineering project. It needs reliable distance labels and training examples spanning object sizes, orientations, ranges, lighting and camera configurations. Evaluation should include held-out capture sessions and physical objects, not only nearby frames from the same sequence.
A learned model can use context and familiar-size cues, but those cues do not remove the underlying ambiguity. An unfamiliar object size or a changed camera setup may produce a plausible yet incorrect estimate. Compare any learned method against the geometric baseline and report error across the operating range.
Choose camera and lens around repeatability
Start camera selection with the farthest distance, the required field of view and the smallest usable image feature. Browse area scan cameras and use the camera finder to compare interfaces and imaging characteristics after setting those requirements.
The LS-CMR-0053 uses GigE and a rolling shutter. The LS-CMR-0166 uses USB3 and a rolling shutter. These are camera examples to investigate for a stationary-target evaluation:
- Sensor format
- 1/1.7"
- Lens mount
- C-mount
- Sensor format
- 1/1.7"
- Interface
- USB3
For moving targets, review shutter behavior, exposure duration and acquisition timing before applying the same method. Motion blur changes measured edges; rolling-shutter distortion can also alter apparent shape during motion.
Select machine vision lenses for sensor coverage, field of view, usable focus range and measurement stability. The lens finder helps narrow the optical options, but nominal resolution labels alone do not establish distance accuracy.
The LS-FFL-0602 and LS-FFL-0567 are C-mount lens examples to evaluate. Their inclusion is not a validated camera-lens pairing:
- Type
- Machine vision fixed
- Sensor format
- 1"
- Type
- Machine vision fixed
- Sensor format
- 1.1"
Confirm mount compatibility, image-circle coverage, mechanical clearance and focus at the complete intended range before choosing a combination. Keep focus fixed after calibration; refocusing can change image scale as well as sharpness.
Verify performance before using the estimate
Build a validation grid rather than checking one convenient image. For example, test five depths, three horizontal positions and three permitted orientations. That gives 5 × 3 × 3 = 45 conditions before repeated captures or different physical samples are added.
At each condition, record ground-truth depth, estimated depth, pixel width and whether the intended feature was fully visible. Separate signed bias from frame-to-frame variation. A stable estimate can still have a large systematic error.
Set an acceptance limit from the application requirement. Record maximum absolute error as well as an average, and inspect failures rather than discarding them silently. Reject readings when the feature is clipped, occluded, too small or outside the validated pose range.
A short commissioning checklist is:
- Confirm the physical dimension and its manufacturing tolerance.
- Freeze focus, zoom, resolution and coordinate transformations.
- Document the distance origin and any mechanical offset.
- Validate near, middle and far operating distances.
- Check off-center targets and permitted object rotation.
- Define an invalid-reading state instead of always displaying a number.
Recognize when another distance method is needed
Apparent size is the wrong primary cue when object dimensions are unknown, pose changes freely, or occlusion removes the measured feature. Better calibration cannot recover information that the image does not contain.
Stereo uses the displacement between corresponding image features rather than assuming object width. Its useful range and uncertainty depend on baseline, calibration and correspondence quality; the stereo baseline selection guide explains those tradeoffs. Other depth-sensing methods have their own surface, lighting and range limitations.
When combining a detector with a depth image, first establish image alignment and decide which object pixels represent the required distance. A rectangle containing foreground edges and background should not be treated as one uniform depth surface.
Do not use an unvalidated monocular estimate as a machine safety function. For inspection or measurement, establish the allowable error and invalid-reading behavior before integration.
Start a candidate setup with the camera configurator, or contact the applications team with your object dimensions, orientation limits, distance range, field of view and allowable error.
Questions
Can one camera estimate object distance without a depth sensor?
Yes, if a known physical dimension and controlled viewing geometry provide the missing scale. A fixed camera can be calibrated to convert a repeatable pixel width into axial depth. Unknown object size, changing orientation and occlusion can make the same calculation unreliable or ambiguous.
Is a detector bounding box accurate enough for distance measurement?
Not necessarily. A detector box is intended to localize an object, and its boundaries may change with visibility, background or detection behavior. For measurement, use identifiable physical edges or landmarks inside the detected region and validate their repeatability across the full operating range.
Will adding distance labels make a detector predict distance?
Additional labels only help when the training pipeline and prediction model are designed to use them. Distance regression requires compatible outputs, a suitable loss and representative ground-truth data. Calculating distance after detection is often a simpler baseline when object dimensions and orientation are controlled.
When should a distance calibration be repeated?
Recalibrate after changes to zoom, focus, lens, image scaling or camera configuration that affect projection. Moving the camera also invalidates any world-plane calibration. Even without deliberate changes, periodic checks against a reference target help identify mounting movement or an altered measurement pipeline.
When is stereo or another depth sensor a better choice?
Consider depth sensing when physical object size is unknown, orientation varies substantially or the necessary feature is frequently hidden. Select the method against range, surface appearance, lighting and allowable error. A depth sensor still needs calibration, validity checks and correct alignment with detector coordinates.



