DroneImageExtractor#
- class rapidtools.processing.DroneImageExtractor(images: Sequence[DroneCamera] | str | Path, save_directory: str | Path, max_views: int = 4, crop_buffer: float | str = '20%', position_error_m: float = 2.0, angle_error_deg: float = 1.0, min_crop_px: int = 256, max_crop_px: int | None = None, overlay_asset_outline: bool = True, outline_shape: str = 'corners', outline_width: int | float | str = '0.8%', outline_color: str | tuple[int, int, int] = 'red', image_prefix: str = 'drone', attribute_prefix: str = 'drone', max_workers: int = 4, cancel_event: Event | None = None, refine_poses: bool = False, refine_prompt: str = 'building', refine_model: Any | None = None, refine_min_overlap: float = 0.2, selector: DroneViewSelector | None = None, **selector_options: Any)[source]#
Bases:
objectAttach to every asset the drone photos that show the most of it.
A pipeline step for perspective (oblique or nadir) drone photographs. For each asset it selects a small set of photos that together cover as much of the asset’s walls and roof as the flight captured (see
DroneViewSelector), crops each chosen photo around the asset and attaches the crops asImageAssetobjects, most informative first. Analysis steps downstream then see a compact multi-view record of every asset.The step also writes what the flight did and did not capture to each asset:
drone_view_coverage(quality-weighted share of the surface shown),drone_seen_fraction,drone_coverage_roofanddrone_coverage_north/_east/_south/_west,drone_unseen_sidesandn_drone_views.- Parameters:
images (Sequence[DroneCamera] | str | Path) – The flight: cameras from
read_drone_images(), or a folder of photos to read with its default settings.save_directory (str | Path) – Where the crops are written.
max_views (int) – Most photos kept per asset. Defaults to 4.
crop_buffer (float | str) – Margin around the projected asset: a percentage of its longest side (
'20%', the default) or pixels.position_error_m (float) – Expected error of the camera positions. The crop grows by the pixel shift such an error causes at the asset’s distance, so a pose that is a little off still frames the asset. Defaults to 2.0 (consumer GPS).
angle_error_deg (float) – Expected error of the gimbal angles, handled the same way. Defaults to 1.0.
min_crop_px (int) – Crops are grown to at least this many pixels on their shorter side. Defaults to 256.
max_crop_px (int | None) – Crops whose longer side exceeds this are scaled down to it before saving. Vision-language models spend time and memory in proportion to the pixels they are given, and a building does not need thousands of them.
None(default) keeps the photo’s resolution.overlay_asset_outline (bool) – Mark the asset on each crop so a model knows which building is meant. Defaults to
True.outline_shape (str) –
'corners'(default: brackets around the projected asset, leaving it uncovered),'bbox','rotated_bbox','convex_hull'or'geometry'.outline_width (int | float | str) – Stroke width in pixels or percent of the shorter crop side. Defaults to
'0.8%'.outline_color (str | tuple[int, int, int]) – PIL color of the mark. Defaults to
'red'.image_prefix (str) – Prefix of crop file names and image IDs. Defaults to
'drone'.attribute_prefix (str) – Prefix of the attributes written to assets. Defaults to
'drone'.max_workers (int) – Photos opened concurrently. Defaults to 4.
cancel_event (Event | None) – Cooperative cancellation flag.
refine_poses (bool) – Correct each photo’s pose error in the image before cropping: SAM 3 segments the buildings in every photo a view was chosen from, and the projected footprints are shifted to where they overlap those buildings best (see
estimate_image_shift()). The crop and the mark then sit on the building even when the GPS or the compass was a few meters or degrees off. Needs a GPU for reasonable speed and enough standing structures in view to lock on to; photos where the match is weak keep the recorded pose. Defaults toFalse.refine_prompt (str) – What SAM 3 is asked to segment. Defaults to
'building'.refine_model (Any | None) – A loaded
SAM3Inference(or anything with itsrun_inference); loaded on demand otherwise.refine_min_overlap (float) – Smallest overlap score (intersection over union of projected footprints and segmented buildings) at which a shift is trusted. Defaults to 0.2.
selector (DroneViewSelector | None) – A configured selector to use instead of building one.
**selector_options – Any other
DroneViewSelectorargument, for exampledefault_height_m,ground_elevation,roof_weight,min_gainorobstacles.
Example
>>> from rapidtools.core import PhysicalAssetCollection >>> from rapidtools.processing import DroneImageExtractor >>> buildings = PhysicalAssetCollection.from_geojson( ... 'footprints.geojson' ... ) >>> extractor = DroneImageExtractor( ... 'flight_01/', save_directory='drone_crops', max_views=4, ... default_height_m=6.0, ... ) >>> buildings = extractor(buildings) >>> extractor.coverage_gaps().to_geojson('gaps.geojson')
Methods
Walls the last run found no photo of (see
DroneViewSelector.coverage_gaps()).Pixel box cropped out of a chosen photo.
- crop_box(view: SelectedView) tuple[int, int, int, int][source]#
Pixel box cropped out of a chosen photo.
The projected asset plus the
crop_buffermargin plus the shift the expected pose error causes at the asset’s distance, grown tomin_crop_pxand clipped to the photo.Example
>>> box = extractor.crop_box(view)
- coverage_gaps() PhysicalAssetCollection[source]#
Walls the last run found no photo of (see
DroneViewSelector.coverage_gaps()).Example
>>> extractor.coverage_gaps().to_geojson('gaps.geojson')