ORB matching example

This commit is contained in:
Ankit Agrawal
2013-11-29 20:49:14 +01:00
committed by Johannes Schönberger
parent a53d93e0f7
commit ba92c47497
4 changed files with 67 additions and 6 deletions
+60
View File
@@ -0,0 +1,60 @@
import numpy as np
from skimage import data
from skimage import transform as tf
from skimage.feature import pairwise_hamming_distance, brief, match_binary_descriptors, corner_harris, corner_peaks, keypoints_orb, descriptor_orb
from skimage.color import rgb2gray
from skimage import img_as_float
import matplotlib.pyplot as plt
rotate = 0.5
translate = (-100, -200)
scaling = (1.5, 1.5)
match_threshold = 0.40
match_cross_check = True
img_color = data.lena()
tform = tf.AffineTransform(scale = scaling, rotation=rotate, translation=translate)
transformed_img_color = tf.warp(img_color, tform)
img = rgb2gray(img_color)
transformed_img = rgb2gray(transformed_img_color)
keypoints1, orientations1, scales1 = keypoints_orb(img, n_keypoints=250)
keypoints1.shape
descriptors1, keypoints1 = descriptor_orb(img, keypoints1, orientations1, scales1)
keypoints1.shape
descriptors1.shape
keypoints2, orientations2, scales2 = keypoints_orb(transformed_img, n_keypoints=250)
keypoints2.shape
descriptors2, keypoints2 = descriptor_orb(transformed_img, keypoints2, orientations2, scales2)
keypoints2.shape
descriptors2.shape
pairwise_hamming_distance(descriptors1, descriptors2)
matched_keypoints, mask1, mask2 = match_binary_descriptors(keypoints1, descriptors1, keypoints2, descriptors2, cross_check=match_cross_check, threshold=match_threshold)
matched_keypoints.shape
# Plotting the matched correspondences in both the images using matplotlib
src = matched_keypoints[:, 0, :]
dst = matched_keypoints[:, 1, :]
src_scale = 10 * (scales1[mask1] + 1) ** 2
dst_scale = 10 * (scales2[mask2] + 1) ** 2
img_combined = np.concatenate((img_as_float(img_color), img_as_float(transformed_img_color)), axis=1)
offset = img.shape
fig, ax = plt.subplots(nrows=1, ncols=1)
plt.gray()
ax.imshow(img_combined, interpolation='nearest')
ax.axis('off')
ax.axis((0, 2 * offset[1], offset[0], 0))
ax.set_title('Matched correspondences : Rotation = %f; Scale = %s; Translation = %s; threshold = %f; cross_check = %r' % (rotate, scaling, translate, match_threshold, match_cross_check))
for m in range(len(src)):
ax.plot((src[m, 1], dst[m, 1] + offset[1]), (src[m, 0], dst[m, 0]), '-', color='g')
ax.scatter(src[m, 1], src[m, 0], src_scale[m], facecolors='none', edgecolors='b')
ax.scatter(dst[m, 1] + offset[1], dst[m, 0], dst_scale[m], facecolors='none', edgecolors='b')
plt.show()
+3 -2
View File
@@ -9,7 +9,8 @@ from .corner import (corner_kitchen_rosenfeld, corner_harris,
hessian_matrix_eigvals)
from .corner_cy import corner_moravec, corner_orientations
from .template import match_template
from ._brief import brief, match_keypoints_brief
from ._brief import brief
from .match import match_binary_descriptors
from .util import pairwise_hamming_distance
from .censure import keypoints_censure
from .orb import keypoints_orb, descriptor_orb
@@ -30,7 +31,7 @@ __all__ = ['daisy',
'match_template',
'brief',
'pairwise_hamming_distance',
'match_keypoints_brief',
'match_binary_descriptors',
'keypoints_censure',
'corner_fast',
'corner_orientations',
+3 -3
View File
@@ -19,7 +19,7 @@ OFAST_MASK = np.array([[0, 0, 1, 1, 1, 0, 0],
def keypoints_orb(image, n_keypoints=200, fast_n=9, fast_threshold=0.20,
harris_k=0.05, downscale=np.sqrt(2), n_scales=3):
harris_k=0.05, downscale=np.sqrt(2), n_scales=4):
"""Detect Oriented Fast keypoints.
@@ -134,7 +134,7 @@ def keypoints_orb(image, n_keypoints=200, fast_n=9, fast_threshold=0.20,
def descriptor_orb(image, keypoints, orientations, scales,
downscale=np.sqrt(2), n_scales=5):
downscale=np.sqrt(2), n_scales=4):
"""Compute rBRIEF descriptors of input keypoints.
Parameters
@@ -206,7 +206,7 @@ def descriptor_orb(image, keypoints, orientations, scales,
curr_scale_orientation = orientations[curr_scale_mask]
border_mask = _mask_border_keypoints(curr_image, curr_scale_kpts,
dist=13)
dist=14)
curr_scale_kpts = curr_scale_kpts[border_mask]
curr_scale_orientation = curr_scale_orientation[border_mask]
+1 -1
View File
@@ -9,7 +9,7 @@ import numpy as np
from libc.math cimport sin, cos, M_PI, round
pos = np.loadtxt("orb_descriptor_positions.txt", dtype=np.int8)
pos = np.loadtxt("skimage/feature/orb_descriptor_positions.txt", dtype=np.int8)
pos0 = np.ascontiguousarray(pos[:, :2])
pos1 = np.ascontiguousarray(pos[:, 2:])