im_list = [] for path in im_paths: im = np.array(Image.open(path).convert("L")) im_list.append(imtools.imresize(im,(int(im.shape[1]/2),int(im.shape[0]/2)))) matchscores = np.zeros((nbr_images,nbr_images)) for i in range(nbr_images): for j in range(i,nbr_images): # only compute upper triangle print('comparing ', im_paths[i], im_paths[j]) l1,d1 = sift.detect_and_compute(im_list[i]) l2,d2 = sift.detect_and_compute(im_list[j]) matches = sift.match_twosided(d1,d2) nbr_matches = np.sum(matches > 0) print('number of matches = ', nbr_matches) matchscores[i,j] = nbr_matches # copy values for i in range(nbr_images): for j in range(i+1,nbr_images): # no need to copy diagonal matchscores[j,i] = matchscores[i,j] threshold = 2 # min number of matches needed to create link g = pydot.Dot(graph_type='graph') # don't want the default directed graph for i in range(nbr_images): for j in range(i+1,nbr_images):
from PIL import Image import numpy as np import pylab as plt from common import imtools from common import sift im1 = np.array(Image.open("data/climbing_1_small.jpg").convert("L")) im2 = np.array(Image.open("data/climbing_2_small.jpg").convert("L")) kp1, desc1 = sift.detect_and_compute(im1) kp2, desc2 = sift.detect_and_compute(im2) print('starting matching') matches = sift.match_twosided(desc1, desc2) plt.figure("SIFT Rock Wall 2-Side Matching") plt.gray() sift.plot_matches(im1, im2, kp1, kp2, matches) plt.show()
import pickle from common import objects3d from common import homography from common import camera from common import sift im_book_frontal = np.array(Image.open('data/book_frontal.JPG')) im_book_perspective = np.array(Image.open('data/book_perspective.JPG')) # Compute features l0, d0 = sift.detect_and_compute(im_book_frontal) l1, d1 = sift.detect_and_compute(im_book_perspective) # Match features and estimate homography matches = sift.match_twosided(d0, d1) ndx = matches.nonzero()[0] fp = homography.make_homog(l0[ndx, :2].T) ndx2 = [int(matches[i]) for i in ndx] tp = homography.make_homog(l1[ndx2, :2].T) # This differs from the book: Swap coordinates in the from/to points because they are row/col # whereas the Camera plots are x/y. If they aren't swapped before goint into the # H_from_ransac method, H will not be computed correctly for the camera translation. fp_xy = np.array([fp[1, :], fp[0, :], fp[2, :]]) tp_xy = np.array([tp[1, :], tp[0, :], tp[2, :]]) model = homography.RansacModel() H = homography.H_from_ransac(fp_xy, tp_xy, model)[0] # camera calibration K = camera.book_calibration((747, 1000))