Skip to content

02 Perspective correction of tall vehicles (optional, after Step 1)

Entry function:

from trajlab.processing.perspective import PerspectiveParams, correct_perspective

result = correct_perspective(tracks, params=PerspectiveParams(correction="class_offset_empirical_view"))
tracks, estimate = result.tracks, result.estimate

Purpose

Drone and camera detections give the center of the top of a bounding box. For tall vehicles (HGVs, buses) the roof is displaced away from the camera's ground point (relief displacement), so their lateral position d is biased relative to cars by up to 2–3 m. Without correction, HGVs drift across lane boundaries, are assigned to the wrong lane, and are "overtaken" inside their own lane. This was the largest single error source on HGV-rich data (Site 1, campaign 1b: 24–33 % HGVs).

Interface

Pipeline step Requires columns Produces columns Further output columns
perspective pos_lat — —

Corrects pos_lat of the rows of the class group hgv (class labels such as Truck, Heavy Vehicle, Bus, Trailer, HGV, case-insensitive; trajlab.analysis.quality.lane_metrics.HGV_CLASSES) in place, right after the projection and before the alignment (so the road-edge profile is not pulled by displaced HGVs). The applied correction is stored in the run metadata (perspective).

Parameter Default Description
perspective.correction 'none' "none" (default), "lateral_class_offset" (geometric model) or "constant_class_offset" (one median lateral shift per class group, the simpler alternative of the ablation) or "class_offset_empirical" (the constant shift, re-estimated on the corrected data until the residual HGV-minus-car offset is below tol_m; the first estimate is biased towards zero because shifted HGVs are partly assigned to the neighboring lane) or "class_offset_empirical_view" (one iterated empirical offset per camera view, the method of the ANT 2027 paper; views from the HGV band profile or view_boundaries_m) or "joint_gmm" (experimental: joint estimation with the lane geometry; not recommended, it did worse than the empirical offsets on the evaluation data).
perspective.kappa None Class group -> kappa [-], e.g. {"hgv": -0.095}. None: estimated by a first diagnostic pass of the pipeline (needs at least two lanes with HGVs).
perspective.d_c_m None Lateral position [m] of the camera's ground point in this direction's projected pos_lat frame.
perspective.offset_m None constant_class_offset: class group -> lateral shift [m] subtracted from pos_lat; None: median class-minus-car offset from a first diagnostic pass.
perspective.min_points 30 Minimum rows per class, lane and 50 m bin in the diagnostic pass.
perspective.max_iter 4 class_offset_empirical: maximum diagnostic passes.
perspective.tol_m 0.05 class_offset_empirical: stop when the absolute residual offset is below this [m].
perspective.max_offset_m 2.5 class_offset_empirical: safety limit; an estimate above this [m] or one that has not converged after max_iter passes is not applied (warning). The estimate needs cars and HGVs in the same lane; without them it can diverge.
perspective.joint_offset_scope 'global' joint_gmm (experimental): the HGV offset is a parameter of the restricted lane mixture, estimated jointly with the lane geometry on a car-only aligned frame; "global" (one offset per direction), "lane" (one per lane, hierarchical prior) or "piecewise" (one per section, smoothness prior).
perspective.joint_tau_m 1.5 joint_gmm: prior SD of the offset [m], delta ~ N(0, tau^2) (weak; about the largest offsets seen on the recordings of the ANT 2027 paper).
perspective.joint_lane_tau_m 0.5 joint_gmm / "lane": SD of the lane offsets around their common mean [m].
perspective.joint_lane_min_sep_m 2.5 joint_gmm / "lane": minimum distance [m] of the displaced HGV centers of adjacent lanes (about an HGV width), i.e. delta_j - delta_{j+1} <= dmu - min_sep. Without it, converging lane offsets can describe one HGV lane as two (non-identifiable); None disables.
perspective.joint_section_m 300 joint_gmm / "piecewise": section length [m].
perspective.joint_smooth_tau_m 0.3 joint_gmm / "piecewise": SD of the change between neighboring sections [m].
perspective.joint_hgv_lane_alpha 0.5 joint_gmm: strength of a weak Dirichlet prior on the HGV lane weights favoring the right lanes (alpha from 1 + strength for lane 1 to 1 for the leftmost lane; 0 = uniform). Breaks the delta / delta - dmu ambiguity.
perspective.joint_hgv_exclude_left_lane True joint_gmm: no HGVs in the leftmost lane where there are three or more lanes (StVO section 7(3c)); removes the ambiguity "lane j with delta_j" vs "lane j+1 with delta_j - dmu" for the middle lane.
perspective.joint_mode_tie_nats 0.05 joint_gmm: candidate offsets (local maxima of the profile, refined) whose log posterior is within this many nats per HGV point of the best count as equivalent; among them the one with the largest HGV share in the right lane is used.
perspective.joint_profile True joint_gmm: evaluate the profile log posterior of the global offset (identifiability diagnosis, stored in the run metadata); its local maxima are the candidate start values. Without it the candidates start from -2, -1, 0, 1 and 2 m.
perspective.joint_profile_range_m 3 joint_gmm: the profile log posterior of the global offset is evaluated on [-range, range] [m].
perspective.joint_profile_step_m 0.05 grid step of that profile [m].
perspective.joint_max_outer 20 joint_gmm: maximum outer iterations of the offset update.
perspective.joint_tol_m 0.01 joint_gmm: stop when the offset changes by less than this [m].
perspective.joint_estimate None joint_gmm: estimate of an earlier run (delta_global, delta_lane or delta_section as in the run metadata); skips the estimation, e.g. to reuse it for a second Step 5 method. With scope "lane" or "piecewise" and only delta_global given, the global stage is taken from it and only the lane / section offsets are estimated. Defaults to None (estimate).
perspective.view_detection 'hgv_band' class_offset_empirical_view: how the camera-view boundaries along s are found: "hgv_band" (steps of the label-free HGV band relative to the car lane centers) or "seams" (tracking evidence: track starts/ends and lateral jumps).
perspective.view_boundaries_m None fixed view boundaries along s [m] instead of the detection.
perspective.view_offsets_m None with view_boundaries_m: fixed HGV offset per view [m] (estimate of an earlier run, e.g. for a second Step 5 method); skips the estimation.
perspective.view_bin_m 50 bin length of the HGV band profile [m].
perspective.view_min_segment_m 150 minimum view length [m].
perspective.view_min_jump_m 0.6 minimum offset step between views [m].
perspective.view_min_hgv 300 minimum HGV samples per view; fewer: the direction-wide estimate is used there.
perspective.view_min_car 1000 minimum car samples per view.
perspective.view_blend_m 25 the offsets are blended linearly over +-view_blend_m around each boundary [m].
perspective.view_max_offset_m 5 per-view safety limit [m] (larger: the direction-wide estimate).
perspective.view_ambiguous_pp 5 readings delta / delta +- dmu closer than this (percentage points of HGV samples within 0.5 m of a car lane center) are decided by the keep-right share and flagged ambiguous.
perspective.view_robust_reading True robust reading of the per-view offset: the lane-1 share ignores samples in the auxiliary-lane zones, and the keep-right check is skipped when the center criterion separates the best reading from the next by at least view_robust_margin_pp. Defaults to True since 1.0 (False: the earlier reading rule without these two changes).
perspective.view_robust_margin_pp 10 see view_robust_reading [percentage points].
perspective.view_max_abs_delta_m None readings with \|delta\| above this [m] are not considered (e.g. 2 m for top-down drones; keep None for oblique set-ups). Only with view_robust_reading.

Method

Geometric model (correction = "lateral_class_offset")

Relief displacement of the box center relative to cars: $\Delta p = \kappa_c\,(p - c)$ with $\kappa_c = h_{\mathrm{eff},c} / H$ (effective height over flight height). In Frenet coordinates on a near-straight road: $\Delta d = \kappa\,(d - d_c)$, $\Delta s = \kappa\,(s - s_c)$. Estimation from a first diagnostic pass: per lane and 50 m bin the median d of the class minus that of cars (rows outside lane changes and excursions, ≥ min_points rows each), then weighted least squares $\Delta d = \kappa\,d_{car} + b_0 + \beta (s - \bar s)$, $d_c = -b_0/\kappa$ (needs ≥ 2 lanes with the class). Correction (exact inverse): $d = d_{obs} - \frac{\kappa}{1+\kappa}(d_{obs} - d_c)$. The longitudinal component is not corrected (the camera position s_c is not identifiable from lateral offsets). The model and its estimation are chosen for this library; sources on the position errors of drone detections are Sánchez Morales et al. (2020), Páncsics et al. (2024) and Fonod et al. (2025) (references).

Empirical class shift (correction = "class_offset_empirical", used in the evaluation of the ANT 2027 paper)

One constant lateral shift per direction for the HGV group, $d \leftarrow d - \delta_{hgv}$:

  1. Diagnostic pass without correction (heuristic lanes, Savitzky-Golay kinematics): $r_1$ = median over (lane, 50 m bin) of $\mathrm{median}\,d_{HGV} - \mathrm{median}\,d_{car}$.
  2. Apply the accumulated shift $\delta \leftarrow \delta + r_i$ and re-estimate the residual on the corrected data, until $|r_i| <$ tol_m (0.05 m) or max_iter (4) passes. A single estimate is biased towards zero because shifted HGVs are partly assigned to the neighboring lane.
  3. Safety limit: the shift is not applied if $|\delta| >$ max_offset_m (2.5 m) or the iteration did not converge. The iteration drives the residual to zero by construction and can converge to a wrong fixed point when a lane has HGVs but no cars to compare with.

constant_class_offset is the single-estimate variant (ablation baseline); offset_m fixes the shift from configuration instead of estimating it.

Joint lane geometry and HGV offset (correction = "joint_gmm", experimental)

The HGV offset becomes a parameter of the restricted lane mixture of Step 4 (see 06) instead of a quantity measured relative to assigned lanes:

  • Data: rows aligned with a car-only lower-bound profile (alignment.profile_classes), Step 4 windows (≥ 30 cars, auxiliary-lane zones excluded, lane count from lane_count_zones).
  • Model per window: cars $\sum_j w_j N(\mu + j\Delta\mu, \sigma^2)$, HGVs $\sum_j v_j N(\mu + j\Delta\mu + \delta_j, \sigma_h^2)$ with $\delta_j = \delta$ ("global"), per lane ("lane", $\delta_j \sim N(\bar\delta, 0.5^2)$) or per section ("piecewise", random-walk prior). Priors as the restricted GMM plus $\delta \sim N(0, 1.5^2)$ and a weak Dirichlet prior on $v$ favoring the right lanes. MAP-ECM with closed-form updates; the offset is shared across windows (pooled sufficient statistics).
  • Identifiability: HGVs in lane $j$ with $\delta$ and in lane $j+1$ with $\delta - \Delta\mu$ fit a homogeneous road equally well. Candidates are the local maxima of the profile log posterior $L(\delta)$ (−3…+3 m), each refined; candidates within 0.05 nats per HGV point of the best are equivalent and the one with the largest HGV share in the right lane is used. Lane scope: displaced HGV centers of adjacent lanes ≥ 2.5 m apart, no HGVs in the left lane of three or more.
  • Output: pos_lat of HGV rows shifted by the estimate (per lane: offset of the lane whose displaced center is nearest); estimate, candidates, profile and diagnosis in the run metadata.

The joint estimate is not recommended; see the design choices below.

Design choices

The choices below are made for this library unless a paper is named; the evidence for each is given under "Source" (a test, a script of applications/ant2027/ or a measurement named in the text).

  • The offset is estimated per recording and direction and never transferred. The relief displacement depends on the camera set-up. On 22 recordings (44 directions) the sign differs between campaigns (campaign 1a / one direction of campaign 2 −1.4…−1.8 m, campaign 1b +1.0…+1.3 m). A sign check of the wiring (offset = HGV − car median, subtracted before the alignment) found no error. Source: tests/processing/perspective/test_perspective.py.
  • The empirical shift is iterated, not estimated once. A single estimate is biased towards zero because shifted HGVs are partly assigned to the neighboring lane. With the iteration the residual is ≤ 0.10 m in 44 of 44 directions; the single estimate leaves up to 0.58 m in HGV-rich directions. Source: tests/processing/perspective/test_perspective.py (iteration).
  • Safety limit max_offset_m = 2.5 m. The iteration drives the residual to zero by construction, so a small residual cannot tell a right from a wrong fixed point. A lane with HGVs but no cars gives a synthetic estimate of −4.03 m for a true +1.6 m; in one of 44 real directions the estimate was −3.02 m, and forced shifts of that size mainly moved HGVs into the left lane instead of reducing errors. The next largest real estimate is 2.41 m. Source: tests/processing/perspective/test_perspective.py (safety limit).
  • The geometric model (lateral_class_offset) is an option, not the default correction. On a recording with HGVs in only one lane per direction its two parameters are determined exactly by two lane positions, so the linear model cannot be checked, and the longitudinal displacement it implies at the section ends is not credible for a section composed of several camera views. It needs at least two lanes with HGVs. Source: Sánchez Morales et al. (2020), Fonod et al. (2025) for the model.
  • The joint estimate (joint_gmm) is not recommended. On 44 directions every scope (global, per lane, per section) gave more in-lane overtakings than the iterated empirical estimate. Causes: the offset is identified only up to one lane width and the wrong reading ($\delta - \Delta\mu$) won with a clear posterior preference in two directions; the car-only alignment profile it needs is wrong where lane 1 carries mostly HGVs (2–5 m off the all-class profile); and where the offset steps at camera seams, one offset per direction or lane cannot follow it. Source: tests/processing/perspective/test_joint_offset.py (estimation and identifiability on synthetic data).

Validation and limitations

  • tests/processing/perspective/test_perspective.py (model inverse, estimation, iteration, safety limit), tests/processing/perspective/test_joint_offset.py, tests/processing/perspective/test_views.py (per-view offset).
  • The offset is not constant everywhere. Behind the camera hand-over of campaign 1b the HGV − car offset has opposite signs in different lanes (+2 / −1.3 m; relief displacement around the nadir of a second camera). A constant shift averages these out and moves HGVs the wrong way in one lane; the HMM reacts to this with more in-lane overtakings (09) and campaign 1b shows many short spurious HGV "lane changes" (07). The offset per camera view (correction = "class_offset_empirical_view", described in Method) follows such steps between views.
  • The restricted lane geometry (06) presupposes the correction on HGV-rich data.