Registration#

class rapidtools.processing.aerial_evidence.Registration(ties: ndarray, shifts: ndarray, project: Callable[[float, float], tuple[float, float]], unproject: Callable[[float, float], tuple[float, float]], radius_m: float = 40.0, min_ties: int = 3)[source]#

Bases: object

Where a street survey and an overhead image disagree, place by place.

The positions of a street survey come from its receiver, those of an orthomosaic from its own georeferencing, and the two differ by a shift that changes slowly along the route: neighboring objects are off by much the same amount. Objects found in both sources are tie points. Each gives the shift at its place, and the shift anywhere is the median over the tie points around it, so a car that was parked again a meter away between the two captures does not move its neighbors.

The tie points need not be of the class that is moved. Parked cars, seen well from the street and from above, register hydrants and anything else the same frames placed. An object is never moved by its own tie, only by those around it.

Variables:
  • ties (numpy.ndarray) – (n, 2) positions of the tie points from the street survey, in local meters.

  • shifts (numpy.ndarray) – (n, 2) street position minus image position at each.

  • project (Callable[[float, float], tuple[float, float]]) – (lon, lat) -> (x, y) in those meters.

  • unproject (Callable[[float, float], tuple[float, float]]) – Its inverse.

  • radius_m (float) – Tie points this close to a place tell its shift.

  • min_ties (int) – Fewest of them for a local shift. With fewer, twice the radius is searched, and failing that the shift of the whole survey (the median over all tie points) is used.

Example

>>> from shapely.geometry import Point
>>> from rapidtools.processing.street_localization import local_projection
>>> project, unproject = local_projection(-117.4, 47.7)
>>> street = [unproject(10.0 * i, 5.0) for i in range(8)]
>>> image = [Point(*unproject(10.0 * i - 1.0, 5.5)).buffer(1e-5)
...          for i in range(8)]
>>> registration = Registration.from_detections(street, image)
>>> east, north, n = registration.shift_at(*unproject(35.0, 5.0))
>>> round(east, 1), round(north, 1), n
(1.0, -0.5, 8)

Methods

from_detections

Pair street positions with overhead detections of the same class.

shift_at

Shift of the street survey against the image at one place.

to_image

Move a geometry placed from the street to where the image has it.

classmethod from_detections(positions: Sequence[tuple[float, float]], detections: Sequence[BaseGeometry], *, max_distance_m: float = 3.0, radius_m: float = 40.0, min_ties: int = 3) → Registration[source]#

Pair street positions with overhead detections of the same class.

The shift of the whole survey is found first (estimate_offset()); with it taken out, every street position whose nearest detection center lies within half of max_distance_m, and is nearest to it in turn, is a tie point.

Parameters:
  • positions – Street-level object positions as (lon, lat).

  • detections – Overhead outlines of the same class in longitude and latitude.

  • max_distance_m – Farthest pairing while the overall shift is sought; ties are paired within half of it afterward.

  • radius_m – See Registration.

  • min_ties – See Registration.

Returns:

Registration – With no tie points when the two do not pair up; it then moves nothing.

shift_at(lon: float, lat: float) → tuple[float, float, int][source]#

Shift of the street survey against the image at one place.

A tie point at the place itself (within a quarter meter) is left out, so an object is not moved onto its own overhead outline.

Returns:

tuple[float, float, int] – (east, north) in meters, street minus image, and the number of tie points it rests on (all of them when the overall shift had to be used, 0 when there are none).

to_image(geometry: BaseGeometry) → tuple[BaseGeometry, float, float, int][source]#

Move a geometry placed from the street to where the image has it.

Returns:

tuple – The moved geometry (longitude and latitude), the (east, north) shift in meters that was taken off, and the number of tie points behind it.