merge_pieces

Contents

merge_pieces#

rapidtools.processing.street_tracking.merge_pieces(estimates: Sequence[ObjectEstimate], project: Callable[[float, float], tuple[float, float]], bearing_sigma_deg: float = 0.75, object_length_m: float = 5.0, search_radius_m: float = 15.0, judge_range_m: float = 20.0, closest_k: int = 5, on_fraction: float = 0.6, evidence_fraction: float = 0.25, size_ratio: float = 1.3, solid_distance_m: float = 2.5, solid_parallax_deg: float = 45.0, solid_sigma_m: float = 0.25, far_fraction: float = 0.3, far_distance_m: float = 4.0) → list[ObjectEstimate][source]#

Fold objects that are really pieces of a neighbour into that neighbour.

Where several vehicles line up along the camera’s line of sight (a driveway seen end-on, cars down the street) the tracker can slide from one to the next, and a detector can cut one car in two past a pole or into a front and a rear. The result is a second object a few metres from a well-located one, made of sightings that show the same vehicle. The two share frames, which the other merge stages take as proof of two objects, so they are judged here on what their sightings show instead.

A less precise object B joins a more precise triangulated A when:

  • most of B’s rays pass near A (as merge_by_rays() tests),

  • B’s closest_k sightings within judge_range_m, the ones that define what B is, mostly (on_fraction) show A: the ray passes within a quarter object size of A and the ground-contact range lands within max(2.5 m, 35 %) of A’s position. This is decisive on its own, whatever B’s own triangulation says: a low-parallax track lands metres from where its sightings point,

  • no more than evidence_fraction of those frames contradict it, where a contradiction is a frame in which A’s own sighting shows A while B’s does not (both sightings showing A are two pieces of one vehicle; A’s sighting not showing A was the tracker astray and proves nothing). One such frame in which A was seen within judge_range_m settles it on its own: the vehicle is right there, large and unmistakable, and B’s outline is something else,

  • B is not larger than size_ratio times A (or the class size): a motorhome behind a pickup lines up and fails only on size,

  • and, when B is solid (parallax over solid_parallax_deg and uncertainty under solid_sigma_m) so that its own position is trustworthy, it lies within solid_distance_m of A.

A B never seen within judge_range_m has no dependable position of its own whatever its parallax: ground-contact ranges read from far away are off by a third, so its triangulation lands metres along the line of sight from the vehicle. Its closest sightings, wherever they are, define it: the ray test above runs over them rather than the whole track, whose far slivers may point anywhere. When their ground points do not land on A but their ranges fit the range_ratio_bounds band, B still joins if its triangulation lies within far_fraction of its nearest range (at least far_distance_m) of A. It may only join an A that was itself seen within judge_range_m: the close pass is the dependable one and keeps the position.

A keeps its position; it gains the sightings of B that show it.

Parameters:
  • estimates – Merged candidates with members set.

  • project – Local metre projection.

  • bearing_sigma_deg – One-sigma bearing error.

  • object_length_m – Typical size of the class.

  • search_radius_m – Only pairs this close are examined.

  • judge_range_m – Sightings farther than this carry ranges too noisy to judge and are ignored.

  • closest_k – How many of B’s closest sightings are judged.

  • on_fraction – Share of them that must show A.

  • evidence_fraction – Share of contradicting frames that blocks the merge.

  • size_ratio – Largest size of B relative to A (at least the class size) still taken for one object.

  • solid_distance_m – Farthest a solid B may lie from A.

  • solid_parallax_deg – Parallax from which B counts as solid.

  • solid_sigma_m – Uncertainty below which B counts as solid.

  • far_fraction – How far, as a fraction of its nearest range, a B never seen within judge_range_m may lie from A.

  • far_distance_m – Least distance allowed for such a B.

Returns:

list[ObjectEstimate] – The remaining objects, in input order.

Example

>>> merged = merge_pieces(estimates, project)