Skip to content
Snippets Groups Projects
Commit 5cde01ff authored by Filip Naiser's avatar Filip Naiser
Browse files

increased time limit in nearest, also added check on shapes in AE

parent cc2511b8
No related branches found
No related tags found
No related merge requests found
......@@ -38,8 +38,8 @@ def nearest(means: np.ndarray, data: np.ndarray) -> (np.ndarray, np.ndarray):
def create_db(imgs_visual_words: np.ndarray, num_words: int) -> csr_matrix:
"""
Create database [num_words, num_imgs] of word weights represented as csr_matrix. Details explained at tutorial page.
imgs_visual_words is of dimensions [num_imgs, visual_words_in_img]. Number of visual_words_in_img differs for
each img.
imgs_visual_words is an array of arrays of length num_imgs. Each np.array is a list of visual words in an image.
Number of visual_words_in_img differs for each img.
:param imgs_visual_words:
:param num_words:
......@@ -71,8 +71,8 @@ def create_db_tfidf(imgs_visual_words: np.ndarray, num_words: int, idf: np.ndarr
def get_idf(imgs_visual_words: np.ndarray, num_words: int) -> np.ndarray:
"""
Create Inverse Document Frequency of shape: [num_words, num_imgs]
imgs_visual_words is of dimensions [num_imgs, visual_words_in_img]. Number of visual_words_in_img differs for
each img.
imgs_visual_words is an array of arrays of length num_imgs. Each np.array is a list of visual words in an image.
Number of visual_words_in_img differs for each img.
idf is of shape: [num_words, 1]
:param imgs_visual_words:
......
%% Cell type:code id: tags:
``` python
# TODO:
"""
corrs=corrm2m(qvw, vw, relevant, max_tc, max_MxN)
qvw - visual words in query image
vw - K x visual words
relevant - list of relevant img indices (of len K)
return a list of lists of tentative correspondences (K x Tk), K - #imgs, Tk - tentative
corrs between query and k-th relevant image (qvw_i, vw_i)
"""
# TODO: what is a minimum number of features in common
# M x N - cartesian product of the same visual word instances
# maximum min(N,M) TRUE correspondences
# sort common visual words w.r.t. MxN
```
%% Cell type:code id: tags:
``` python
from image_search import *
import scipy.io
```
%% Cell type:code id: tags:
``` python
data = scipy.io.loadmat('data/mpvdb_haff2.mat')['data'].T
# idf = getidf(VW, 10000);
# DB = createdb_tfidf(VW, 10000, idf);
#
# opt = [];
# opt.max_tc=600;
# opt.max_MxN=10;
# opt.max_spatial=50;
# % directory where you unzipped mpvimgs.zip
# opt.root_dir='./';
# % opt.subplot=1;
# opt.threshold=8;
```
%% Output
---------------------------------------------------------------------------
NameError Traceback (most recent call last)
<ipython-input-1-30f4565421d9> in <module>
----> 1 data = scipy.io.loadmat('data/mpvdb_haff2.mat')['data'].T
2 # idf = getidf(VW, 10000);
3 # DB = createdb_tfidf(VW, 10000, idf);
4 #
5 # opt = [];
NameError: name 'scipy' is not defined
%% Cell type:code id: tags:
``` python
```
import numpy as np
from scipy.sparse import csr_matrix
def get_tentative_correspondencies(
query_vw: np.ndarray, vw: np.ndarray, relevant_idxs: np.ndarray, max_tc: int, max_MxN: int) -> np.ndarray:
"""
Compute tentative correspondencies.
:param query_vw: [num_keypoints_in_query x 1]
:param vw: [num_imgs x num_words_in_img] visual_words
:param relevant_idxs: [num_imgs, ]
:param max_tc: maximum tentative correspondences
:param max_MxN: maximum pairs
:return: correspondencies np.ndarray of shape [num_correspondencies x 2]
"""
correspondencies = np.zeros((0, 2), dtype=np.int)
return correspondencies
def get_A_matrix_from_geom(geom: np.ndarray):
"""
returns a matrix
[
a11 a12 x
a21 a22 y
0 0 1
]
:param geom:
:return: 3x3 matrix
"""
return np.array([
[geom[2], geom[3], geom[0]],
[geom[4], geom[5], geom[1]],
[0, 0, 1],
])
def ransac_affine(
q_geom: np.ndarray, geometries: np.ndarray, correspondencies: np.ndarray, relevant: np.ndarray,
inlier_threshold: float) -> (np.ndarray, np.ndarray):
"""
:param q_geom: query geometry of shape [num_keypoints x 6]
:param geometries: np.ndarray of object of len num_images. each object is np.ndarray [num_keypoints_in_img x 6]
:param correspondencies: [num_correspondencies x 2]
:param relevant: relevant indices
:param inlier_threshold: maximum transformed point to corresponding point distance to be considered as an inlier
:return: (As, inliers_counts), where As are estimated affine matrices for each image and number of inliers in each image
"""
K = len(relevant)
As = np.zeros((K, 3, 3))
inliers_counts = np.zeros((K, ))
return As, inliers_counts
def query_spatial_verification(
query_visual_words: np.ndarray, query_geometry: np.ndarray, bbox: list, visual_words: np.ndarray,
geometries: np.ndarray, db: csr_matrix, idf: np.ndarray, params: dict) -> (np.ndarray, np.ndarray, np.ndarray):
"""
:param query_visual_words: [num_keypoints_in_query x 1]
:param query_geometry: query geometry of shape [num_keypoints x 6]
:param bbox: list [x, y, xx, yy]
:param visual_words: [num_imgs x num_words_in_img] visual_words
:param geometries: np.ndarray of object of len num_images. each object is np.ndarray [num_keypoints_in_img x 6]
:param db: [num_words, num_imgs]
:param idf: Inverse Document Frequency. Shape: [num_words, 1]
:param params: dictionary, important keys here: minimum_score, max_tc, max_MxN, use_query_expansion
:return:
"""
num_relevant = ... # you need to get number based on scores and params['minimum_score']
inliers_counts = np.zeros((num_relevant, ), dtype=np.int)
relevant_idxs = np.zeros((num_relevant, ), dtype=np.int)
As = np.zeros((num_relevant, 3, 3))
return inliers_counts, relevant_idxs, As
source diff could not be displayed: it is too large. Options to address this: view the blob.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment