Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Slightly improve backend code
  • Loading branch information
stocc committed Aug 16, 2022
commit 904172a250a381497633a8d67287b8b1c0a19116
4 changes: 1 addition & 3 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ def closest_pano_to_coord(lat, lon):
smallest_distance = distance
closest = pano
#print(x,y)
return jsonify(date="asdf",lat = closest.lat, lon = closest.lon, panoid = str(closest.panoid), region_id = str(closest.region_id), unknown10 = closest.unknown10, unknown11 = closest.unknown11, heading = closest.heading())
return jsonify(date=closest.date,lat = closest.lat, lon = closest.lon, panoid = str(closest.panoid), region_id = str(closest.region_id), unknown10 = closest.unknown10, unknown11 = closest.unknown11, heading = closest.heading)



Expand Down Expand Up @@ -129,7 +129,6 @@ def relay_full_pano(panoid, region_id, zoom):
image = None

TILE_SIZE = round(heic_array[0].width * (256 / 5632))
print("TILE_SIZE:", TILE_SIZE)
WIDTH_SIZE = round(heic_array[0].width * (1024 / 5632))
widths, heights = zip(*(i.size for i in heic_array))
total_width, max_height = (sum(widths)-WIDTH_SIZE), max(heights)
Expand All @@ -153,7 +152,6 @@ def relay_full_pano(panoid, region_id, zoom):

@app.route("/panodbg/<int:panoid>/<int:region_id>/<int:zoom>/")
def relay_pano_dbg(panoid, region_id, zoom):
print("Starting")
heic_array = []
for i in range(4):
heic_bytes = fetch_pano_segment(panoid, region_id, i, zoom, auth)
Expand Down
7 changes: 2 additions & 5 deletions lookaround/lookaround/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import requests

from .proto import MapTile_pb2
from .geo import wgs84_to_tile_coord
from .geo import wgs84_to_tile_coord, heading_from_unkown10_unknown11
from .panorama import LookaroundPanorama

from google.protobuf.json_format import MessageToJson
Expand All @@ -27,7 +27,7 @@ def get_coverage_tile(tile_x, tile_y, tile_z = 17):
pano_obj = LookaroundPanorama(
pano.panoid,
tile.unknown13[pano.region_id_idx].region_id,
lat, lon, pano.unknown4.unknown10, pano.unknown4.unknown11)
lat, lon, pano.unknown4.unknown10, pano.unknown4.unknown11, heading_from_unkown10_unknown11(pano.unknown4.unknown10, pano.unknown4.unknown11))
pano_obj.date = datetime.fromtimestamp(int(pano.timestamp) / 1000.0)
panos.append(pano_obj)
return panos
Expand Down Expand Up @@ -58,9 +58,6 @@ def _get_coverage_tile_raw(tile_x, tile_y, tile_z = 17):
response = requests.get("https://gspe76-ssl.ls.apple.com/api/tile?", headers=headers)
tile = MapTile_pb2.MapTile()
tile.ParseFromString(response.content)
json_obj = MessageToJson(tile)
with open("tile.json", "w") as f:
f.write(json_obj)
return tile

def get_pano_segment_url(panoid, region_id, segment, zoom, auth):
Expand Down
49 changes: 49 additions & 0 deletions lookaround/lookaround/geo.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,52 @@ def tile_coord_to_wgs84(x, y, zoom):
world_coord = (pixel_coord[0] / scale, pixel_coord[1] / scale)
lat_lon = mercator_to_wgs84(world_coord[0], world_coord[1])
return lat_lon



'''
Approximate heading of the panorama, assuming the POV is facing
to the left of the Apple Car in cthe direction of driving.
'''
def heading_from_unkown10_unknown11(unknown10, unknown11):
# Whatever is the logic behind this?
# Who at Apple thought of these values?

# unknown10
# These are the extreme values of unkown10 I have observed in a random selection of about 1000 tiles.
# The values are in two clusters.
# In the range [1,2159] you're looking more west than east.
# In the range [14318,16383] you're looking more east than west.
westmin = 1
westmax = 2159
eastmin = 16383 # looking (north/south) and very slightly east
eastmax = 14318 # looking slightly (north/south) directly east

# unknown11
# This is slightly more speculative
northmin = 8204 # this is likely lower
northmax = 6054
southmin = 8204 # this is likely lower
southmax = 10173


ew=0
if unknown10 < westmax:
# Looking west
ew = -(float(unknown10 - westmin) / float(westmax - westmin))
elif unknown10 > eastmax:
# Looking east
ew = (float(unknown10 - eastmin) / float(eastmax - eastmin))

ns=0
if unknown11 <= northmin:
# Looking north
ns = (float(unknown11 - northmin) / float(northmax - northmin))
else:
ns = -(float(unknown11 - southmin) / float(southmax - southmin))


r = math.degrees(math.atan2(ew,ns))
if r < 0:
r += 360
return r
53 changes: 3 additions & 50 deletions lookaround/lookaround/panorama.py
Original file line number Diff line number Diff line change
@@ -1,66 +1,19 @@
import math
class LookaroundPanorama:
def __init__(self, panoid, region_id, lat, lon, unknown10, unknown11):
def __init__(self, panoid, region_id, lat, lon, unknown10, unknown11, heading):
self.panoid = panoid
self.region_id = region_id
self.lat = lat
self.lon = lon
self.unknown10 = unknown10
self.unknown11 = unknown11
self.date = None
self.heading = heading

'''
Approximate heading of the panorama, assuming the POV is facing
to the left of the Apple Car in cthe direction of driving.
'''
def heading(self):
# Whatever is the logic behind this?
# Who at Apple thought of these values?

# unknown10
# These are the extreme values of unkown10 I have observed in a random selection of about 1000 tiles.
# The values are in two clusters.
# In the range [1,2159] you're looking more west than east.
# In the range [14318,16383] you're looking more east than west.
westmin = 1
westmax = 2159
eastmin = 16383 # looking (north/south) and very slightly east
eastmax = 14318 # looking slightly (north/south) directly east

# unknown11
# This is slightly more speculative
northmin = 8204 # this is likely lower
northmax = 6054
southmin = 8204 # this is likely lower
southmax = 10173


ew=0
if self.unknown10 < westmax:
# Looking west
ew = -(float(self.unknown10 - westmin) / float(westmax - westmin))
elif self.unknown10 > eastmax:
# Looking east
ew = (float(self.unknown10 - eastmin) / float(eastmax - eastmin))

ns=0
if self.unknown11 <= northmin:
# Looking north
ns = (float(self.unknown11 - northmin) / float(northmax - northmin))
else:
ns = -(float(self.unknown11 - southmin) / float(southmax - southmin))


print(ns,ew)
r = math.degrees(math.atan2(ew,ns))
if r < 0:
r += 360
return r


def __repr__(self):
return str(self)

def __str__(self):
return f"{self.panoid}/{self.region_id} ({self.lat:.6}, {self.lon:.6}) " \
return f"{self.panoid}/{self.region_id} ({self.lat:.6}, {self.lon:.6}) {self.heading}" \
f"[{self.date.strftime('%Y-%m-%d')}]"