DroneCamera#
- class rapidtools.data_sources.DroneCamera(image_id: str, lon: float, lat: float, elevation_m: float, yaw_deg: float, pitch_deg: float, width: int, height: int, focal_px: float, roll_deg: float = 0.0, cx: float | None = None, cy: float | None = None, path: Path | None = None, captured_at: str | None = None, relative_altitude_m: float | None = None, absolute_altitude_m: float | None = None, properties: dict[str, ~typing.Any]=<factory>)[source]#
Bases:
objectOne drone photograph: where the camera was, where it looked, and its lens.
- Variables:
image_id (str) – Identifier of the photo (the file stem by default).
lon (float) – Camera longitude in degrees (WGS 84).
lat (float) – Camera latitude in degrees.
elevation_m (float) – Camera height in the working vertical datum (see the module notes).
yaw_deg (float) – Compass direction the lens looks at.
pitch_deg (float) –
0at the horizon,-90straight down.roll_deg (float) – Roll about the lens axis.
width (int) – Image width in pixels.
height (int) – Image height in pixels.
focal_px (float) – Focal length in pixels.
cx (float | None) – Principal point column; the image center when
None.cy (float | None) – Principal point row; the image center when
None.path (Path | None) – Image file, when the photo is on disk.
captured_at (str | None) – Capture time as written by the camera, if known.
relative_altitude_m (float | None) – Height above the take-off point, if recorded.
absolute_altitude_m (float | None) – GPS altitude, if recorded.
properties (dict[str, Any]) – Anything else worth carrying along.
Example
>>> camera = DroneCamera( ... image_id='a', lon=0.0, lat=0.0, elevation_m=50.0, yaw_deg=0.0, ... pitch_deg=-45.0, width=4000, height=3000, focal_px=3000.0, ... ) >>> round(camera.hfov_deg, 1) 67.4 >>> ground = camera.pixel_to_ground(2000, 1500) # 50 m ahead, due north >>> round(ground[1] * 111320) 50
Methods
Rebuild a camera from
to_dict()output.Ground outline of the photo as
(lon, lat)corners.Unit direction (east, north, up) of the ray through a pixel.
Where the ray through a pixel meets a horizontal ground plane.
Camera center in a local east/north/up frame.
Project
(lon, lat, elevation)points into the photo.Project local east/north/up points into the photo.
JSON-friendly record of the pose (round-trips through
from_dict).- property rotation: ndarray#
World-to-camera rotation (see
rotation_from_angles()).
- position(project: Callable[[float, float], tuple[float, float]])[source]#
Camera center in a local east/north/up frame.
- Parameters:
project –
(lon, lat) -> (x, y)fromlocal_projection().- Returns:
numpy.ndarray –
[x, y, elevation]in meters.
Example
>>> from rapidtools.processing.street_localization import ( ... local_projection, ... ) >>> project, _ = local_projection(0.0, 0.0) >>> camera = DroneCamera('a', 0.0, 0.0, 60.0, 0.0, -90.0, 100, 100, 80.0) >>> [float(v) for v in camera.position(project)] [0.0, 0.0, 60.0]
- project_points(points: ndarray | Sequence[Sequence[float]], project: Callable[[float, float], tuple[float, float]]) tuple[ndarray, ndarray][source]#
Project local east/north/up points into the photo.
- Parameters:
points –
N x 3array of local coordinates in meters.project – The local projection the points were made with.
- Returns:
tuple[numpy.ndarray, numpy.ndarray] –
N x 2pixel coordinates (column, row) and the depth of each point along the lens axis. Points behind the camera have a depth of zero or less and meaningless pixel coordinates.
Example
>>> from rapidtools.processing.street_localization import ( ... local_projection, ... ) >>> project, _ = local_projection(0.0, 0.0) >>> camera = DroneCamera('a', 0.0, 0.0, 100.0, 0.0, -90.0, 200, 100, 100.0) >>> pixels, depth = camera.project_points([[10.0, 0.0, 0.0]], project) >>> [round(float(v)) for v in pixels[0]], round(float(depth[0])) ([110, 50], 100)
- project_lonlat(points: Iterable[Sequence[float]]) tuple[ndarray, ndarray][source]#
Project
(lon, lat, elevation)points into the photo.- Parameters:
points – Geographic points with elevations in the camera’s vertical datum.
- Returns:
tuple[numpy.ndarray, numpy.ndarray] – Pixels and depths, as
project_points().
Example
>>> camera = DroneCamera('a', 0.0, 0.0, 100.0, 0.0, -90.0, 200, 100, 100.0) >>> pixels, _ = camera.project_lonlat([(0.0, 0.0, 0.0)]) >>> [round(float(v)) for v in pixels[0]] [100, 50]
- pixel_ray(column: float, row: float) ndarray[source]#
Unit direction (east, north, up) of the ray through a pixel.
Example
>>> camera = DroneCamera('a', 0.0, 0.0, 100.0, 90.0, 0.0, 200, 100, 100.0) >>> [round(float(v), 6) + 0.0 for v in camera.pixel_ray(100, 50)] [1.0, 0.0, 0.0]
- pixel_to_ground(column: float, row: float, ground_elevation_m: float = 0.0) tuple[float, float] | None[source]#
Where the ray through a pixel meets a horizontal ground plane.
- Parameters:
column – Pixel column.
row – Pixel row.
ground_elevation_m – Elevation of the plane.
- Returns:
tuple[float, float] | None –
(lon, lat)of the intersection, orNonewhen the ray does not descend to the plane.
Example
>>> camera = DroneCamera('a', 0.0, 0.0, 100.0, 0.0, -90.0, 200, 100, 100.0) >>> lon, lat = camera.pixel_to_ground(100, 50) >>> round(lon, 6) + 0.0, round(lat, 6) + 0.0 (0.0, 0.0)
- ground_footprint(ground_elevation_m: float = 0.0, max_range_m: float = 1000.0) list[tuple[float, float]][source]#
Ground outline of the photo as
(lon, lat)corners.Corners whose rays never reach the ground (the view includes the horizon) are placed
max_range_maway along their direction.Example
>>> camera = DroneCamera('a', 0.0, 0.0, 100.0, 0.0, -90.0, 200, 100, 100.0) >>> len(camera.ground_footprint()) 4