| | import gradio as gr |
| | import cv2 |
| | import gradio as gr |
| | import torch |
| | from torchvision import transforms |
| | import requests |
| | from PIL import Image |
| | from demo import Demo,read_input_image_test,show_result,vis_image_feature |
| | from osm.tiling import TileManager |
| | from osm.viz import Colormap, plot_nodes |
| | from utils.viz_2d import plot_images |
| | import numpy as np |
| | from utils.viz_2d import features_to_RGB |
| | from utils.viz_localization import ( |
| | likelihood_overlay, |
| | plot_dense_rotations, |
| | add_circle_inset, |
| | ) |
| | from osm.viz import GeoPlotter |
| | import matplotlib.pyplot as plt |
| | import random |
| | from geopy.distance import geodesic |
| |
|
| | experiment_or_path = "weight/last-step-checkpointing.ckpt" |
| | |
| | image_path = 'images/00000.jpg' |
| |
|
| | |
| | |
| | model = Demo(experiment_or_path=experiment_or_path, num_rotations=128, device='cpu') |
| |
|
| | def demo_localize(image,long,lat,tile_size_meters): |
| | |
| | |
| | prior_latlon=(lat,long) |
| | image, camera, gravity, proj, bbox, true_prior_latlon = read_input_image_test( |
| | image, |
| | prior_latlon=prior_latlon, |
| | tile_size_meters=tile_size_meters, |
| | ) |
| | tiler = TileManager.from_bbox(projection=proj, bbox=bbox, ppm=1, tile_size=tile_size_meters) |
| | |
| | canvas = tiler.query(bbox) |
| | uv, yaw, prob, neural_map, image_rectified, data_, pred = model.localize( |
| | image, camera, canvas) |
| | prior_latlon_pred = proj.unproject(canvas.to_xy(uv)) |
| |
|
| | map_viz = Colormap.apply(canvas.raster) |
| | map_vis_image_result = map_viz * 255 |
| | map_vis_image_result =show_result(map_vis_image_result.astype(np.uint8), uv, yaw) |
| | |
| | |
| | |
| | |
| | |
| | uab_feature_rgb = vis_image_feature(pred['features_image'][0].cpu().numpy()) |
| | map_viz = cv2.resize(map_viz, (prob.numpy().shape[0], prob.numpy().shape[1])) |
| | overlay = likelihood_overlay(prob.numpy().max(-1), map_viz.mean(-1, keepdims=True)) |
| | (neural_map_rgb,) = features_to_RGB(neural_map.numpy()) |
| | fig=plot_images([image, map_vis_image_result / 255, overlay, uab_feature_rgb, neural_map_rgb], |
| | titles=["UAV image", "map","likelihood","UAV feature","map feature"]) |
| | |
| | |
| | |
| | |
| | |
| |
|
| | |
| | bbox_latlon = proj.unproject(canvas.bbox) |
| | plot2 = GeoPlotter(zoom=16.5) |
| | plot2.raster(map_viz, bbox_latlon, opacity=0.5) |
| | plot2.raster(likelihood_overlay(prob.numpy().max(-1)), proj.unproject(bbox)) |
| | plot2.points(prior_latlon[:2], "red", name="location prior", size=10) |
| | plot2.points(proj.unproject(canvas.to_xy(uv)), "black", name="argmax", size=10) |
| | plot2.bbox(bbox_latlon, "blue", name="map tile") |
| | |
| | return fig,plot2.fig,str(prior_latlon_pred) |
| | |
| | |
| | title = "MapLocNet" |
| | |
| | description = "UAV Vision-based Geo-Localization Using Vectorized Maps" |
| |
|
| | |
| | outputs = gr.Plot() |
| | interface = gr.Interface(fn=demo_localize, |
| | inputs=["image", |
| | gr.Number(label="Prior location-longitude)"), |
| | gr.Number(label="Prior location-longitude)"), |
| | gr.Radio([64, 128, 256], label="Search radius (meters)", info="vectorized map size"), |
| | |
| | |
| | ], |
| | outputs=["plot","plot","text"], |
| | title=title, |
| | description=description, |
| | examples=[['images/00000.jpg',-122.435941445631,37.75704325989902,128]]) |
| | interface.launch(share=True) |