mirrorworld.mapillary: Mapillary¶
Mapillary has a documented public API and needs a free access token (MLY|... from
https://www.mapillary.com/dashboard/developers): pass access_token= or set MAPILLARY_ACCESS_TOKEN.
Imagery is CC BY-SA 4.0. Images can be 360° panoramas or ordinary photos (is_pano).
Finding images¶
- find_panoramas(lat, lon, radius=25, limit=None, panos_only=False, session=None, access_token=None)[source]¶
Finds images within a radius around a point, closest first.
This reads the coverage tiles that overlap the circle, because Mapillary’s bounding-box search fails in densely covered areas.
- Parameters:
lat (float) – Latitude of the center point.
lon (float) – Longitude of the center point.
radius (float) – (optional) Search radius in meters. Defaults to 25.
limit (int | None) – (optional) Maximum number of results. Defaults to no limit.
panos_only (bool) – (optional) Only return 360° panoramas. Defaults to False.
session (Session) – (optional) A requests session.
access_token (str) – (optional) Mapillary access token. Defaults to
MAPILLARY_ACCESS_TOKEN.- Returns:
A list of MapillaryPanorama objects.
- Return type:
- async find_panoramas_async(lat, lon, session, radius=25, limit=None, panos_only=False, access_token=None)[source]¶
- find_panorama_by_id(panoid, session=None, access_token=None)[source]¶
Fetches the full metadata of an image, including camera parameters and image URLs.
- Parameters:
- Returns:
A MapillaryPanorama object, or None if no image with this ID exists.
- Return type:
MapillaryPanorama | None
- async find_panorama_by_id_async(panoid, session, access_token=None)[source]¶
- Parameters:
- Return type:
MapillaryPanorama | None
- get_coverage_tile(tile_x, tile_y, session=None, access_token=None)[source]¶
Fetches all images on a Mapillary coverage tile.
The tiles are XYZ tiles at zoom level 14 (about 1.5 km across at mid latitudes). The returned objects carry the location, capture time, heading, panorama flag, sequence and uploader; call
find_panorama_by_id()for camera details and image URLs.
- Parameters:
- Returns:
A list of MapillaryPanorama objects (empty if there is no coverage).
- Return type:
- async get_coverage_tile_async(tile_x, tile_y, session, access_token=None)[source]¶
- Parameters:
- Return type:
- get_coverage_tile_by_latlon(lat, lon, session=None, access_token=None)[source]¶
Same as
get_coverage_tile(), but for fetching the tile on which a point is located.
- Parameters:
- Returns:
A list of MapillaryPanorama objects.
- Return type:
- async get_coverage_tile_by_latlon_async(lat, lon, session, access_token=None)[source]¶
- Parameters:
- Return type:
- get_sequence(sequence_id, session=None, access_token=None)[source]¶
Lists the IDs of the images in a sequence, in capture order.
Usage sample:
from mirrorworld import mapillary panos = mapillary.find_panoramas(47.6062, -122.3321, radius=50, panos_only=True) pano = mapillary.find_panorama_by_id(panos[0].id) print(pano.date, pano.camera_type, pano.permalink) mapillary.download_panorama(pano, f"{pano.id}.jpg", size="original")Async:
from mirrorworld import mapillary from aiohttp import ClientSession async with ClientSession() as session: panos = await mapillary.find_panoramas_async(47.6062, -122.3321, session, radius=50) await mapillary.download_panorama_async(panos[0], f"{panos[0].id}.jpg", session, size="2048")
Downloading images¶
- get_panorama(pano, size='original', session=None, access_token=None)[source]¶
Downloads an image and returns it as PIL image.
- Parameters:
pano (MapillaryPanorama | int) – The image, or its ID. Metadata without image URLs (e.g. from a coverage tile) is completed with
find_panorama_by_id()first.size (str) – (optional)
256,1024,2048(width in pixels) ororiginal. Defaults tooriginal.session (Session) – (optional) A requests session.
access_token (str) – (optional) Mapillary access token. Defaults to
MAPILLARY_ACCESS_TOKEN.- Returns:
A PIL image.
- Return type:
Image
- async get_panorama_async(pano, session, size='original', access_token=None)[source]¶
- Parameters:
pano (MapillaryPanorama | int)
session (ClientSession)
size (str)
access_token (str)
- Return type:
Image
- download_panorama(pano, path, size='original', pil_args=None, session=None, access_token=None)[source]¶
Downloads an image to a file. If the chosen format is JPEG, Exif metadata (and XMP GPano metadata for 360° panoramas) is included.
- Parameters:
pano (MapillaryPanorama | int) – The image, or its ID.
path (str) – Output path.
size (str) – (optional)
256,1024,2048ororiginal. Defaults tooriginal.pil_args (dict) – (optional) Additional arguments for PIL’s Image.save method, e.g.
{"quality":100}. Defaults to{}.session (Session) – (optional) A requests session.
access_token (str) – (optional) Mapillary access token. Defaults to
MAPILLARY_ACCESS_TOKEN.- Return type:
None
Map features, detections and point clouds¶
Objects triangulated from many images (utility poles, manholes, junction boxes, street lights, hydrants, traffic signs, …), per-image semantic segmentations and structure-from-motion point clouds.
- find_map_features(lat, lon, radius=50, values=None, layer='point', session=None, access_token=None)[source]¶
Finds map features (triangulated objects such as utility poles or manholes) around a point, closest first.
- Parameters:
lat (float) – Latitude of the center point.
lon (float) – Longitude of the center point.
radius (float) – (optional) Search radius in meters. Defaults to 50.
values (Iterable[str] | None) – (optional) Keep only these classes. An entry ending in
--matches as a prefix, e.g.["object--support--utility-pole", "object--manhole", "regulatory--"]. Defaults to all.layer (str) – (optional)
pointortraffic_sign. Defaults topoint.session (Session) – (optional) A requests session.
access_token (str) – (optional) Mapillary access token. Defaults to
MAPILLARY_ACCESS_TOKEN.- Returns:
A list of MapFeature objects.
- Return type:
- async find_map_features_async(lat, lon, session, radius=50, values=None, layer='point', access_token=None)[source]¶
- find_map_feature_by_id(feature_id, session=None, access_token=None)[source]¶
Fetches a map feature with its facing direction and the IDs of the images it was detected in.
- Parameters:
- Returns:
A MapFeature object, or None if no feature with this ID exists.
- Return type:
MapFeature | None
- async find_map_feature_by_id_async(feature_id, session, access_token=None)[source]¶
- Parameters:
- Return type:
MapFeature | None
- get_map_features_tile(tile_x, tile_y, layer='point', session=None, access_token=None)[source]¶
Fetches all map features (triangulated objects) on a coverage tile at zoom level 14.
- Parameters:
tile_x (int) – X coordinate of the tile.
tile_y (int) – Y coordinate of the tile.
layer (str) – (optional)
point(poles, manholes, junction boxes, street lights, hydrants, …) ortraffic_sign. Defaults topoint.session (Session) – (optional) A requests session.
access_token (str) – (optional) Mapillary access token. Defaults to
MAPILLARY_ACCESS_TOKEN.- Returns:
A list of MapFeature objects.
- Return type:
- async get_map_features_tile_async(tile_x, tile_y, session, layer='point', access_token=None)[source]¶
- get_detections(pano, session=None, access_token=None)[source]¶
Fetches Mapillary’s semantic segmentation of an image: one polygon set per detected object or surface (road, sidewalk, curb, vegetation, sky, poles, manholes, …).
- Parameters:
pano (MapillaryPanorama | int) – The image, or its ID.
session (Session) – (optional) A requests session.
access_token (str) – (optional) Mapillary access token. Defaults to
MAPILLARY_ACCESS_TOKEN.- Returns:
A list of Detection objects with polygons in normalized image coordinates.
- Return type:
- async get_detections_async(pano, session, access_token=None)[source]¶
- Parameters:
pano (MapillaryPanorama | int)
session (ClientSession)
access_token (str)
- Return type:
- get_point_cloud(pano, session=None, access_token=None)[source]¶
Downloads the structure-from-motion reconstruction that an image belongs to: a colored point cloud of the surroundings plus the poses of all images in the reconstruction.
- Parameters:
pano (MapillaryPanorama | int) – The image, or its ID.
session (Session) – (optional) A requests session.
access_token (str) – (optional) Mapillary access token. Defaults to
MAPILLARY_ACCESS_TOKEN.- Returns:
A PointCloud, or None if the image has no reconstruction.
- Return type:
PointCloud | None
- async get_point_cloud_async(pano, session, access_token=None)[source]¶
- Parameters:
pano (MapillaryPanorama | int)
session (ClientSession)
access_token (str)
- Return type:
PointCloud | None
Usage sample:
from mirrorworld import mapillary poles = mapillary.find_map_features(47.68, -122.30, radius=150, values=["object--support--utility-pole", "object--junction-box"]) pole = mapillary.find_map_feature_by_id(poles[0].id) # adds the images it was seen in detections = mapillary.get_detections(pole.image_ids[0]) # polygons in 0..1 image coordinates cloud = mapillary.get_point_cloud(pole.image_ids[0]) # cloud.xyz, cloud.rgb, cloud.to_wgs84()
Data classes¶
- class MapillaryPanorama(id, lat, lon, date=None, heading=None, is_pano=None, sequence_id=None, creator_id=None, organization_id=None, quality_score=None, computed_lat=None, computed_lon=None, computed_heading=None, elevation=None, computed_elevation=None, camera_type=None, camera_parameters=None, make=None, model=None, width=None, height=None, creator_username=None, image_urls=None)[source]¶
Metadata of a Mapillary image.
Mapillary hosts both 360° panoramas and ordinary (perspective) photos;
is_panotells them apart. The class is named like the other providers’ for consistency.ID, latitude and longitude are always present. Coverage tiles provide the fields up to
quality_score;mirrorworld.mapillary.find_panorama_by_id()fills in the rest.
- Parameters:
id (int)
lat (float)
lon (float)
date (datetime | None)
heading (float | None)
is_pano (bool | None)
sequence_id (str | None)
creator_id (int | None)
organization_id (int | None)
quality_score (float | None)
computed_lat (float | None)
computed_lon (float | None)
computed_heading (float | None)
elevation (float | None)
computed_elevation (float | None)
camera_type (str | None)
camera_parameters (list | None)
make (str | None)
model (str | None)
width (int | None)
height (int | None)
creator_username (str | None)
- heading: float | None = None¶
Heading in radians as recorded by the camera, where 0 is north and π/2 is east.
- camera_parameters: list | None = None¶
Intrinsics, e.g. focal length and radial distortion for perspective cameras.
- class MapFeature(id, lat, lon, value, layer, first_seen=None, last_seen=None, aligned_direction=None, image_ids=None, distance=None)[source]¶
An object that Mapillary detected in several images and triangulated to a map position, e.g. a utility pole, manhole, junction box, street light, fire hydrant or traffic sign.
The full list of values is at https://www.mapillary.com/developer/api-documentation/points and https://www.mapillary.com/developer/api-documentation/traffic-signs.
- Parameters:
- aligned_direction: float | None = None¶
Facing direction in radians (traffic signs), from
find_map_feature_by_id().
- class Detection(id, value, polygons, created_at=None)[source]¶
A segmentation of one object in one image.
- Parameters:
- polygons: List[List[List[Tuple[float, float]]]]¶
Polygons, each a list of rings, each a list of (x, y) points normalized to 0..1 of the image width and height with the origin at the top left. The first ring of a polygon is its outline; further rings are holes. For 360° panoramas the coordinates refer to the equirectangular image.
- class PointCloud(xyz, rgb, reference, reconstruction=<factory>)[source]¶
Points of a Mapillary structure-from-motion reconstruction (OpenSfM), in a local east/north/up frame centered on
reference.
- Parameters:
- xyz: ndarray¶
(N, 3) east, north, up coordinates in meters relative to
reference.
- rgb: ndarray¶
(N, 3) colors, 0..255.
Miscellaneous¶
- build_permalink(id=None, lat=None, lon=None, zoom=17.0)[source]¶
Creates a link to an image, or to a location, on mapillary.com.
- get_access_token(access_token=None)[source]¶
Returns the access token to use for Mapillary requests: the one passed in, or else the
MAPILLARY_ACCESS_TOKENenvironment variable. Tokens (MLY|...) are free from https://www.mapillary.com/dashboard/developers.