From 10ff1359f56f5b6529866d3d513a55af267fb275 Mon Sep 17 00:00:00 2001 From: Mike Busuttil <31480000+MikeBusuttil@users.noreply.github.com> Date: Sat, 30 Sep 2023 02:55:41 -0400 Subject: [PATCH] improved script for fetching images from routes (#30089) * easily target desired camera * easily target desired camera * cleaner authentication fallback old-commit-hash: a21437a7080320453453e792b8e305d1c0c81713 --- tools/scripts/fetch_image_from_route.py | 26 +++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/tools/scripts/fetch_image_from_route.py b/tools/scripts/fetch_image_from_route.py index 471db7ee3e..b59e7c895e 100755 --- a/tools/scripts/fetch_image_from_route.py +++ b/tools/scripts/fetch_image_from_route.py @@ -2,10 +2,16 @@ import sys if len(sys.argv) < 4: - print(f"{sys.argv[0]} ") - print('example: ./fetch_image_from_route.py "02c45f73a2e5c6e9|2020-06-01--18-03-08" 3 500') + print(f"{sys.argv[0]} [front|wide|driver]") + print('example: ./fetch_image_from_route.py "02c45f73a2e5c6e9|2020-06-01--18-03-08" 3 500 driver') exit(0) +cameras = { + "front": "cameras", + "wide": "ecameras", + "driver": "dcameras" +} + import requests from PIL import Image from openpilot.tools.lib.auth_config import get_token @@ -16,22 +22,22 @@ jwt = get_token() route = sys.argv[1] segment = int(sys.argv[2]) frame = int(sys.argv[3]) +camera = cameras[sys.argv[4]] if len(sys.argv) > 4 and sys.argv[4] in cameras else "cameras" -url = 'https://api.commadotai.com/v1/route/'+sys.argv[1]+"/files" -r = requests.get(url, headers={"Authorization": "JWT "+jwt}, timeout=10) +url = f'https://api.commadotai.com/v1/route/{route}/files' +r = requests.get(url, headers={"Authorization": f"JWT {jwt}"}, timeout=10) assert r.status_code == 200 print("got api response") -cameras = r.json()['cameras'] -if segment >= len(cameras): - raise Exception("segment %d not found, got %d segments" % (segment, len(cameras))) +segments = r.json()[camera] +if segment >= len(segments): + raise Exception("segment %d not found, got %d segments" % (segment, len(segments))) -fr = FrameReader(cameras[segment]) +fr = FrameReader(segments[segment]) if frame >= fr.frame_count: raise Exception("frame %d not found, got %d frames" % (frame, fr.frame_count)) im = Image.fromarray(fr.get(frame, count=1, pix_fmt="rgb24")[0]) -fn = "uxxx_"+route.replace("|", "_")+"_%d_%d.png" % (segment, frame) +fn = f"uxxx_{route.replace('|', '_')}_{segment}_{frame}.png" im.save(fn) print(f"saved {fn}") -