示例#1
0
 def load_routes(self, route_ids):
     self.route_ids = route_ids
     for rid in self.route_ids:
         route_path = self.routes_path + '/route' + str(rid) + '/'
         route_data = load_route_naw(route_path,
                                     route_id=id,
                                     query=True,
                                     max_dist=self.dist)
         self.routes_data.append(route_data)
from source.utils import load_route_naw, plot_route, seq_angular_error, animated_window, pre_process
from source import seqnav
import numpy as np

route_id = 1
path = '../new-antworld/exp1/route' + str(route_id) + '/'
# path = '../test_data/route'+ str(route_id) + '/'
route = load_route_naw(path, route_id=route_id, imgs=True, query=True, max_dist=0.2)

plot_route(route)

window = -20
matcher = 'corr'
sets = {'blur': True, 'shape': (180, 50), 'edge_range': (220, 240)}
route_imgs = pre_process(route['imgs'], sets)
test_imgs = pre_process(route['qimgs'], sets)

# nav = perfect_memory.PerfectMemory(route_imgs, matcher)
# recovered_heading = nav.navigate(test_imgs)
nav = seqnav.SequentialPerfectMemory(route_imgs, matcher, window=window)
recovered_heading, window_log = nav.navigate(test_imgs)

traj = {'x': route['qx'], 'y': route['qy'], 'heading': recovered_heading}
traj['heading'] = np.array(traj['heading'])
plot_route(route, traj)

errors, _ = seq_angular_error(route, traj)
print(np.mean(errors))

window_log = np.array(window_log)
示例#3
0
import numpy as np
import numpy.ma as ma
import matplotlib.pyplot as plt
import pickle
import cv2 as cv
from source.utils import nanmae, nan_cor_dist, rmf, rotate, load_route_naw
from source.display import plot_multiline, nans_imgshow

path = 'ODK_office/odk-mask.pickle'
with open(path, 'rb') as handle:
    mask = pickle.load(handle)

route_id = 1
path = 'new-antworld/exp1/route' + str(route_id) + '/'
route = load_route_naw(path, route_id=1, imgs=True)

imgs = route['imgs']
im = cv.resize(imgs[0], (256, 35))
im = im.astype(np.int32)
imm = ma.masked_array(im, mask)

# plt.imshow(rotate(90, imm), cmap='gray')
# plt.show()

# Original image
sims = rmf(im, im, d_range=(-180, 180))
imr = rotate(90, im)
print(np.mean(np.abs(im - imr)))
# Masked image
masked_sims = rmf(imm, imm, d_range=(-180, 180))
figsize = (10, 10)
title = 'D'

traj = data.loc[(data['matcher'] == matcher) & (data['res'] == res) & (data['edge'] == edge) &
                (data['window'] == window) & (data['route_id'] == route_id)]
# traj = data.to_dict(orient='records')[0]
# if window:
#     w_log = literal_eval(traj['window_log'])

errors = traj['errors'].tolist()
errors = np.array(errors[0])
traj = {'x': np.array(traj['tx'].tolist()[0]),
        'y': np.array(traj['ty'].tolist()[0]),
        'heading': np.array(traj['th'].tolist()[0])}

route = load_route_naw(path, route_id=route_id)
if threshold:
    index = np.argwhere(errors > threshold)[0]
    thres = {}
    thres['x'] = traj['x'][index]
    thres['y'] = traj['y'][index]
    thres['heading'] = traj['heading'][index]

fig_save_path = os.path.join(fig_save_path, 'route{}.w{}.m{}.res{}.edge{}.thres{}.png'\
    .format(route_id, window, matcher, res, edge, threshold))

plot_route(route, traj, scale=70, size=figsize, save=True, path=fig_save_path, title=title)


# if window:
#     path = '/home/efkag/Desktop/route' + str(route_id) + '/window-plots/'