mapillary / mapillary-python-sdk

A Python 3 library built on the Mapillary API v4 to facilitate retrieving and working with Mapillary data.
MIT License
39 stars 15 forks source link

[Requirements] 4. Get All Detections For An Image Key #15

Closed Rubix982 closed 3 years ago

Rubix982 commented 3 years ago

Is your feature request related to a problem? Please describe. This issue deals with the 4th requirement from the PRD for extracting all the detections within an image using an image key

Describe the solution you'd like The base requirements are,

  1. Takes image key as argument
  2. Returns JSON with detections (segmentations of the image)

Describe alternatives you've considered NA

Additional context NA

Rubix982 commented 3 years ago
  1. First geometry to pixel_geometry
  2. Convert to GeoJSON format
Rubix982 commented 3 years ago
  1. [X] Converted geometry to pixel_geometry
  2. [X] Converted to GeoJSON!
  3. [X] Checking for image vs map_feature key done!

Sample output,

>>> import mapillary as mly
>>> mly.set_access_token('CLIENT_TOKEN')
{'Status': 'Success'}
>>> mly.get_detections_with_image_key(image_key=1933525276802129)
Response 200 OK received in 588ms
Response 200 OK received in 809ms
{'type': 'FeatureCollection', 'features': [{'type': 'Feature', 'geometry': {'type': 'Point', 'coordinates': [-97.743279722222, 30.270651388889]}, 'properties': {'created_at': '2021-05-20T17:49:01+0000', 'pixel_geometry': 'GjUKBm1weS1vchIVEgIAABgDIg0JhiekKBoqAABKKQAPGgR0eXBlIgkKB3BvbHlnb24ogCB4AQ==', 'value': 'regulatory--no-parking--g2', 'id': '1933525276802129'}}, {'type': 'Feature', 'geometry': {'type': 'Point', 'coordinates': [-97.743279722222, 30.270651388889]}, 'properties': {'created_at': '2021-05-20T18:40:21+0000', 'pixel_geometry': 'GjYKBm1weS1vchIWEgIAABgDIg4J7DjqHxpWAADiAVUADxoEdHlwZSIJCgdwb2x5Z29uKIAgeAE=', 'value': 'information--parking--g1', 'id': '1933525276802129'}}, {'type': 'Feature', 'geometry': {'type': 'Point', 'coordinates': [-97.743279722222, 30.270651388889]}, 'properties': {'created_at': '2021-05-22T07:04:08+0000', 'pixel_geometry': 'Gjh4AgoGbXB5LW9yKIAgEikIARgDIiMJ2hrYGXIFDBEINwMLBwULAAkGCxoHBg8GAQYGIgAKCAQIDw==', 'value': 'object--street-light', 'id': '1933525276802129'}}, {'type': 'Feature', 'geometry': {'type': 'Point', 'coordinates': [-97.743279722222, 30.270651388889]}, 'properties': {'created_at': '2021-05-22T07:58:20+0000', 'pixel_geometry': 'Glh4AgoGbXB5LW9yKIAgEkkIARgDIkMJ5ibeI8oBCAQGDgSCAgasAQR4ApwBAhAADgjGAQEyCDgEdgFaERgHBAcPAbUBB5MBAO0BA0cD9wEDMwGxAQV9Ah0P', 'value': 'object--support--pole', 'id': '1933525276802129'}}, {'type': 'Feature', 'geometry': {'type': 'Point', 'coordinates': [-97.743279722222, 30.270651388889]}, 'properties': {'created_at': '2021-05-22T08:56:39+0000', 'pixel_geometry': 'GmJ4AgoGbXB5LW9yKIAgElMIARgDIk0JhgPcOJICCAcgAwwHQhEwB3oATgooFAIICggCGgcOAwADEAsEDRIFAAcQPyZRHpMBFk0ALwUrDxkRBQsCGQgHChcQCQILDAMOESYXDw==', 'value': 'object--manhole', 'id': '1933525276802129'}}, {'type': 'Feature', 'geometry': {'type': 'Point', 'coordinates': [-97.743279722222, 30.270651388889]}, 'properties': {'created_at': '2021-05-22T10:10:16+0000', 'pixel_geometry': 'GtYCeAIKBm1weS1vciiAIBIVCAEYAyIPCa4usjEiAwwDAAMLBAcPEq8CCAIYAyKoAgmUL4oz6gcpBAMHGQ0FDwcDBR0JEQAfBxEABwQACA0GAwIbCgEGHwwJAQcRDwAJDBMAGQYHCgQCEgoUAAwEAwAHDAMHDwARBQcJAwIdBwsBCQIhAx8PBQ8AAQsEExURA08EBwIVCA8SAQYOEgwIDh4IBAggAwgILghoAzQTTAc6ERgAEggCMAcYAmIBIgIUBAQEEgI8JSoLBAUEAwAFBAEAAwQBAAcEFQQTBwsZARcEBwARBxNJAQceAwAHDhsABQkDAAAHCw8RGBMGAwgVBAEMEQQDCgYACAwCEAQEAAoECBYICBoIBAIIBAQcAxgKDAwDHgsAGRgLEgEAAQQXCCUqDwk33wEiDQABCAwEBAMPCTH9ARoLBgoMBAMPCSycAhoBAAAEAgAP', 'value': 'object--bench', 'id': '1933525276802129'}}, {'type': 'Feature', 'geometry': {'type': 'Point', 'coordinates': [-97.743279722222, 30.270651388889]}, 'properties': {'created_at': '2021-05-22T10:48:57+0000', 'pixel_geometry': 'Gix4AgoGbXB5LW9yKIAgEh0IARgDIhcJ+hvyKUIEDAFqAwwPAAMHAyUCSwQHDw==', 'value': 'object--traffic-light--general-upright', 'id': '1933525276802129'}}, {'type': 'Feature', 'geometry': {'type': 'Point', 'coordinates': [-97.743279722222, 30.270651388889]}, 'properties': {'created_at': '2021-05-22T11:30:54+0000', 'pixel_geometry': 'GjV4AgoGbXB5LW9yKIAgEiYIARgDIiAJphPyLGICEwQzEAsIAAYLEgAOEAIeBaABHwQdBwFhDw==', 'value': 'object--trash-can', 'id': '1933525276802129'}}, {'type': 'Feature', 'geometry': {'type': 'Point', 'coordinates': [-97.743279722222, 30.270651388889]}, 'properties': {'created_at': '2021-05-22T14:53:14+0000', 'pixel_geometry': 'GqkBeAIKBm1weS1vciiAIBJkCAEYAyJeCcAW1CyqAgKFAQhtBNcBCmUE6wIMaQTnAQxdBJcBEHUAoQEMcQJ9EnEGAwYYABYDEAtmBe4BC0YBiAILegBiB6wBAQQAIgECBc4CCWAFxgMHUAWIAQEMAwALFQVBDxI0CAIYAyIuCdoY+hmaAQAEAQABAAEAAQADAAEAAQABAAEAAAMCAAIAAgACAAQAAgACAAIADw==', 'value': 'object--support--pole', 'id': '1933525276802129'}}, {'type': 'Feature', 'geometry': {'type': 'Point', 'coordinates': [-97.743279722222, 30.270651388889]}, 'properties': {'created_at': '2021-05-22T15:00:54+0000', 'pixel_geometry': 'Gi54AgoGbXB5LW9yKIAgEh8IARgDIhkJuCHUKEouAwYACgAWAAYIAxoJDBkCMQAP', 'value': 'object--traffic-light--general-horizontal', 'id': '1933525276802129'}}, {'type': 'Feature', 'geometry': {'type': 'Point', 'coordinates': [-97.743279722222, 30.270651388889]}, 'properties': {'created_at': '2021-05-22T15:07:25+0000', 'pixel_geometry': 'Gml4AgoGbXB5LW9yKIAgEhEIARgDIgsJrBjyKRICFAEADxIfCAIYAyIZCbIY5ig6CLECAH0EEQoCC6QGBbcBApcBDxImCAMYAyIgCaYY5itiCBoDHgAYBAoGAAIHATcGFQGmAQUmDQQBVw8=', 'value': 'object--support--pole', 'id': '1933525276802129'}}, {'type': 'Feature', 'geometry': {'type': 'Point', 'coordinates': [-97.743279722222, 30.270651388889]}, 'properties': {'created_at': '2021-05-22T16:07:01+0000', 'pixel_geometry': 'GkF4AgoGbXB5LW9yKIAgEjIIARgDIiwJxCOoJnoDIQPfAQYHBB4S5gMAvgEGogECtgEDWAEIBQABiwEFLQHbAQM/Dw==', 'value': 'object--support--pole', 'id': '1933525276802129'}}, {'type': 'Feature', 'geometry': {'type': 'Point', 'coordinates': [-97.743279722222, 30.270651388889]}, 'properties': {'created_at': '2021-05-22T19:36:52+0000', 'pixel_geometry': 'Gjl4AgoGbXB5LW9yKIAgEioIARgDIiQJ1hTCKmoCIQINBgAADgFyB2YDkAEFJgOUAQVcBwABFxKnAw8=', 'value': 'object--support--pole', 'id': '1933525276802129'}}]}
>>> mly.get_detections_with_map_feature_key(map_feature_key=1933525276802129)
Response 200 OK received in 622ms
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/saif/MLH/mapillary-python-sdk/mapillary/models/auth.py", line 24, in wrapper
    return f(*args, **kwargs)
  File "/home/saif/MLH/mapillary-python-sdk/mapillary/mapillary.py", line 230, in get_detections_with_map_feature_key
    return detection.get_detections_with_map_feature_key_controller(
  File "/home/saif/MLH/mapillary-python-sdk/mapillary/controller/detection.py", line 38, in get_detections_with_map_feature_key_controller
    valid_key(key=map_feature_key, image=False)
  File "/home/saif/MLH/mapillary-python-sdk/mapillary/controller/rules/key.py", line 28, in valid_key
    raise KeyValidityError(key, image)
models.exceptions.KeyValidityError: KeyValidityError: Given map_feature_key, "1933525276802129" was not valid for map_feature
Rubix982 commented 3 years ago

@cbeddow how to decode the base 64.

cbeddow commented 3 years ago

Some context here: https://forum.mapillary.com/t/detection-api-in-v4/4999/

import base64

import mapbox_vector_tile

base64_string = "Gjh4AgoGbXB5LW9yKIAgEikIARgDIiMJxCXQFHIMAAocACAHFAkIUQMLGQQvCAkcBQwTDAIGCggADw=="

data = base64.decodebytes(base64_string.encode('utf-8'))

detg = mapbox_vector_tile.decode(data)

print(detg)