DroneViewSelector#

class rapidtools.processing.DroneViewSelector(cameras: Sequence[DroneCamera], max_views: int = 4, min_gain: float = 0.03, default_height_m: float = 6.0, height_attribute: str | None = None, ground_elevation: float | str | Callable[[float, float], float] = 0.0, roof_weight: float = 1.0, target_px_per_m: float = 15.0, full_incidence_deg: float = 45.0, max_incidence_deg: float = 85.0, clip_penalty: float = 1.0, diversity: float = 0.15, seen_threshold: float = 0.25, max_range_m: float = 400.0, max_candidates: int = 160, occluder_radius_m: float = 80.0, obstacles: PhysicalAssetCollection | None = None, wall_spacing_m: float = 2.0, wall_levels: int = 2, roof_spacing_m: float = 2.5, point_radius_m: float = 1.0, cancel_event: Event | None = None)[source]#

Bases: object

Pick, for every asset, the drone photos that show the most of it.

Parameters:
  • cameras (Sequence[DroneCamera]) – The flight, from read_drone_images().

  • max_views (int) – Most photos kept per asset. Defaults to 4.

  • min_gain (float) – A further photo is kept only if it adds at least this share of the asset’s surface. Defaults to 0.03.

  • default_height_m (float) – Prism height for assets without a height attribute. Defaults to 6.0 (a two-story house).

  • height_attribute (str | None) – Attribute holding the asset height in meters; when None the usual keys (height_m, height, story counts) are tried.

  • ground_elevation (float | str | Callable) – Elevation of the ground under the assets, in the datum of the camera elevations: one number for flat terrain (default 0, the take-off level when cameras use relative altitude), the name of an asset attribute, or a function (lon, lat) -> elevation such as a DEM lookup.

  • roof_weight (float) – Importance of roof area relative to wall area. Defaults to 1.0; 0 selects for facades only.

  • target_px_per_m (float) – Resolution at which a surface counts as fully resolved. Defaults to 15.

  • full_incidence_deg (float) – Surfaces seen within this angle of their normal get full credit. Defaults to 45.

  • max_incidence_deg (float) – Surfaces seen more obliquely than this do not count. Defaults to 85.

  • clip_penalty (float) – Exponent applied to the share of the asset inside the frame: a photo that cuts the asset off is worth that much less on every patch. 0 disables the penalty. Defaults to 1.0.

  • diversity (float) – Preference for new vantage points among near-equal candidates. Defaults to 0.15.

  • seen_threshold (float) – Quality above which a patch counts as seen in the coverage report. Defaults to 0.25.

  • max_range_m (float) – Photos farther than this from an asset are not considered. Defaults to 400.

  • max_candidates (int) – Photos per asset that get the full occlusion test, the best by unoccluded quality within each viewing direction. Defaults to 160.

  • occluder_radius_m (float) – Neighbors within this distance of an asset can hide it. Defaults to 80.

  • obstacles (PhysicalAssetCollection | None) – Further things that block the view but are not analyzed (tree canopies, buildings outside the collection), as footprints with a height attribute.

  • wall_spacing_m (float) – Distance between wall patches. Defaults to 2.0.

  • wall_levels (int) – Rows of patches up each wall. Defaults to 2.

  • roof_spacing_m (float) – Grid spacing of roof patches. Defaults to 2.5.

  • point_radius_m (float) – Footprint radius given to point assets. Defaults to 1.0.

  • cancel_event (Event | None) – Cooperative cancellation flag checked between assets.

Example

>>> selector = DroneViewSelector(cameras, max_views=3)
>>> view_sets = selector.select(buildings)
>>> view_sets['b12'].coverage_by_side
{'roof': 0.97, 'north': 0.0, 'east': 0.81, 'south': 0.9, 'west': 0.74}

Methods

asset_ground

Ground elevation under an asset.

asset_height

Prism height of an asset in meters (attribute or default).

coverage_gaps

The walls no chosen photo shows, as a collection of line assets.

project_prisms

Outline of every asset of the last select() call in one photo.

select

Choose the view set of every asset.

asset_height(asset: PhysicalAsset) → float[source]#

Prism height of an asset in meters (attribute or default).

asset_ground(asset: PhysicalAsset) → float[source]#

Ground elevation under an asset.

select(assets: Iterable[PhysicalAsset], allowed: Mapping[str, Iterable[str]] | None = None) → dict[str, AssetViewSet][source]#

Choose the view set of every asset.

Parameters:
  • assets – The assets (a collection or any iterable of them). Their footprints also act as occluders for one another.

  • allowed – Optional restriction of the photos considered per asset: asset ID to the image IDs that may be chosen for it. Assets not listed keep the whole flight. Useful for comparing against another way of picking photos, or for limiting an asset to one flight of several.

Returns:

dict[str, AssetViewSet] – One entry per asset with a usable geometry, keyed by asset ID. Assets no photo shows get an empty view set with zero coverage.

Example

>>> view_sets = selector.select(buildings)
>>> [v.camera.image_id for v in view_sets['b12'].views]
['DJI_0101', 'DJI_0178', 'DJI_0033']
project_prisms(camera: DroneCamera) → dict[str, list[tuple[float, float]]][source]#

Outline of every asset of the last select() call in one photo.

Parameters:

camera – The photo.

Returns:

dict[str, list[tuple[float, float]]] – Asset ID to the pixel outline (convex hull) of its projected prism, for the assets in front of the camera whose outline touches the frame.

Example

>>> outlines = selector.project_prisms(cameras[0])
>>> sorted(outlines)[:2]
['b12', 'b13']
static coverage_gaps(view_sets: dict[str, AssetViewSet]) → PhysicalAssetCollection[source]#

The walls no chosen photo shows, as a collection of line assets.

Each line carries the asset it belongs to, the direction the wall faces, its length, and a suggested camera position (fly_to_lon, fly_to_lat, fly_height_m above the ground at the asset, fly_yaw_deg, fly_pitch_deg) from which the wall would be seen squarely. Write it with to_geojson and load it in a flight planner or GIS to see where the survey has holes.

Parameters:

view_sets – Output of select().

Returns:

PhysicalAssetCollection – One LineString asset per unseen wall.

Example

>>> gaps = DroneViewSelector.coverage_gaps(view_sets)
>>> gaps.to_geojson('coverage_gaps.geojson')