Exemplo n.º 1
0
def generate_obs(img_num, n_img, db_rows, obs_out, neogeo_out, flann_time,
                 flann):
    t0 = time.time()
    ft = f5.get_node('/images/sift_features/img_%d' % img_num)
    tret = time.time() - t0
    t1 = time.time()
    windowed = ft.read_where('size > 0.5')
    obs_desc = windowed['descriptor'][-n_img:, :]

    obs_desc = obs_desc.astype(np.float32)
    tsort = time.time() - t1
    t2 = time.time()
    idx, dist = flann.nn_index(obs_desc, 2)
    d_vec = dist[:, 0] / dist[:, 1]
    img_idx = np.where(d_vec < 0.7)[0]
    db_idx = idx[img_idx, 0].astype(np.int)
    flann_time[img_num] = time.time() - t2

    if db_idx.shape[0] > 0:
        pid = db_rows[db_idx]['pair_id']
        flannid, fidx, flanncount = np.unique(pid,
                                              return_counts=True,
                                              return_index=True)
        flannxy = np.array([pdb.unpair(tt) for tt in flannid]).astype(np.int)
        img = utils.plot_on_grid(flannxy[:, 0], flannxy[:, 1], flanncount, xb,
                                 yb)
        neogeo_out[img_num] = np.copy(img)
        obs_likelihood = np.zeros_like(flanncount, dtype=np.float64)
        for fii in np.arange(flannid.shape[0]):
            obs_likelihood[fii] = (1 -
                                   d_vec[img_idx][pid == flannid[fii]]).sum()
        img2 = utils.plot_on_grid(flannxy[:, 0], flannxy[:, 1], obs_likelihood,
                                  xb, yb)
        obs_out[img_num] = np.copy(img2)
Exemplo n.º 2
0
def generate_obs(img_num, n_img, db_rows, obs_out, neogeo_out, flann_time, flann):
    t0 = time.time()
    ft = pd.read_hdf('/media/sean/D2F2E7B2F2E798CD/Users/student/AIEoutput2/feat/' + feat_path.iloc[img_num])
    ftdesc = bcolz.open('/media/sean/D2F2E7B2F2E798CD/Users/student/AIEoutput2/feat/' + descripath.iloc[img_num], 'r')
    tret = time.time() - t0
    t1 = time.time()

    # Here, we need to make sure that we sort the values by response
    n_img = n_img.astype(np.int)
    ft = ft.sort_values(by='response', ascending=False).iloc[:n_img]

    # Then pull the descriptors by the index
    obs_desc = ftdesc[ft.index, :]

    #    windowedindex = ft[ft['size'] > 0.5].index
    #    windowed = ftdesc[windowedindex,:]
    #   #obs_desc = windowed['descriptor'][-n_img:, :]
    #    n_img = n_img.astype(np.int)
    #    obs_desc = windowed[-n_img:, :]
    ##    print(n_img)
    #    print(windowed)
    #    print(obs_desc)

    obs_desc = obs_desc.astype(np.float32)
    tsort = time.time() - t1

    t2 = time.time()
    idx, dist = flann.nn_index(obs_desc, 2)
    d_vec = dist[:, 0] / dist[:, 1]

    img_idx = np.where(d_vec < 0.7)[0]
    # print[img_idx.size]
    db_idx = idx[img_idx, 0].astype(np.int)
    # print[db_idx.size]
    flann_time[img_num] = time.time() - t2
    # print(db_idx.shape[0])brisk

    if db_idx.shape[0] > 0:
        pid = db_rows[db_idx]['pair_id']
        # print(1-d_vec[img_idx])
        dbfeatwlla = np.array(
            (1 - d_vec[img_idx], db_rows[db_idx]['lat'], db_rows[db_idx]['lon'], db_rows[db_idx]['height'])).transpose()
        # print(dbfeatwlla)
        obs_out[img_num, 0:(dbfeatwlla.shape[0]), :] = np.copy(dbfeatwlla)
        print(obs_out[img_num, 0:(dbfeatwlla.shape[0] + 1), :])
        # dbloc[img_num][0:dbfeatwlla.shape[0]] = dbfeatwlla
        flannid, fidx, flanncount = np.unique(
            pid, return_counts=True, return_index=True)
        flannxy = np.array([pdb.unpair(tt)
                            for tt in flannid]).astype(np.int)
        img = utils.plot_on_grid(
            flannxy[:, 0], flannxy[:, 1], flanncount, xb, yb)
        #        print(flannid)
        #        print(flanncount)
        neogeo_out[img_num] = np.copy(img)
Exemplo n.º 3
0
    txmax = dbt.cols.x[int(dbt.colindexes['x'][-1])]
    tymin = dbt.cols.y[int(dbt.colindexes['y'][0])]
    tymax = dbt.cols.y[int(dbt.colindexes['y'][-1])]
    xbounds = np.array((txmin, txmax), dtype=np.int64)
    ybounds = np.array((tymin, tymax), dtype=np.int64)
    xb, yb = neoextent.pad_grid(xbounds, ybounds)

    # Full aggregate tile id
    tid, tidcount = np.unique(dbf.root.sift_db.unique_tiles[:],
                              return_counts=True)
    extent = neoextent.SearchExtent(6, xb, yb, tid, tidcount)

    # Reshape the observations to fit the grid.
    obs_out = np.zeros((obs.shape[0], extent.grid_size, extent.grid_size))
    for ii, i_obs in enumerate(obs):
        obs_out[ii] = nutils.plot_on_grid(obs_xy[:, 0], obs_xy[:, 1], i_obs,
                                          xb, yb)

    neo = core.NeoGeo()
    neo.init_px_from_extent(extent)
    posterior = np.zeros_like(obs_out)

    for ii in np.arange(0, obs_out.shape[0]):
        dpos = np.copy(ned_vel[ii, 0:2])
        dpos_sig = 0.10 * np.linalg.norm(dpos) * np.ones(2)
        neo.motion_model(dpos, dpos_sig)
        neo.update(obs_out[ii])
        posterior[ii] = np.copy(neo.p_x)

    fig = plt.figure(figsize=(10, 10))
    ax = plt.gca()
    oimg = ax.imshow(neo.p_x, cmap='hot', interpolation='Nearest')
Exemplo n.º 4
0
    img_resp = windowed['response']
    img_sort = np.argsort(img_resp)
    obs_desc = windowed['descriptor'][img_sort[-10000:], :]
    # obs_desc = windowed['descriptor']
    obs_desc = obs_desc.astype(np.float32)
    result, dist = flann.nn_index(obs_desc, 1)
    obs_words = np.unique(result, return_counts=True)
    obs_tf_vec = np.zeros(cluster_centers.shape[0])
    obs_tf_vec[obs_words[0]] = obs_words[1]
    obs_tf_vec = obs_tf_vec[mask] / obs_tf_vec[mask].sum()
    obs_tf_idf = obs_tf_vec * idf_term[mask]
    obs_tf_idf = obs_tf_idf / np.linalg.norm(obs_tf_idf)
    d2 = 2 - 2 * np.dot(tf_idf_mask, obs_tf_idf)
    d3 = np.zeros_like(d2)
    d3[np.argsort(d2)[:25]] = 1.0
    img = neoutils.plot_on_grid(tidxy[:, 0], tidxy[:, 1], d2, xb, yb)
    vocab_out[img_num] = np.copy(img)
    print('%d / %d' % (img_num, img_times.nrows))

backup = np.copy(vocab_out)
vocab_out[np.isnan(vocab_out)] = 2.0
vocab_out[vocab_out == 0.0] = 2.0
vocab_out = 2.0 - vocab_out
vocab_out[vocab_out == 0.0] = vocab_out[vocab_out > 0.0].min()

import neogeo.core as core

reload(core)
neo = core.NeoGeo()
neo.init_px_from_extent(extent)
neo.pix_size_m = neoextent.get_average_tile_size(neo.extent)