-
Notifications
You must be signed in to change notification settings - Fork 11
/
plotMatches.m
83 lines (74 loc) · 2.32 KB
/
plotMatches.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
function plotMatches(im1,im2,f1,f2,matches,varargin)
% PLOTMATCHES Plot matching features between images
% PLOTMATCHES(IM1, IM2, F1, F2, MATCHES) displays the images IM1 and
% IM2 overlaying the feature frames F1 and F2 as well as lines
% connecting them as specified by MATCHES. Each column of MATCHES
% paris the frame F1(:, MATCHES(1,i)) to the frame F2(:,
% MATCHES(2,i)).
%
% Options:
%
% plotAllFrames:: false
% Set to true in order to plot all the frames, regardless of
% whether they are matched or not.
%
% Homography:: []
% Set to an homography matrix from the first image to the second
% to display the homography mapping interactively.
% Author: Andrea Vedaldi
opts.plotAllFrames = false ;
opts.homography = [];
opts = vl_argparse(opts, varargin) ;
% plot the images side by side
dh1 = max(size(im2,1)-size(im1,1),0) ;
dh2 = max(size(im1,1)-size(im2,1),0) ;
cla ; set(gca,'ydir', 'reverse') ;
imagesc([padarray(im1,dh1,'post') padarray(im2,dh2,'post')]) ;
hold on ;
axis image off ;
% overlay the matches, if any
o = size(im1,2) ;
if ~isempty(matches)
i1 = matches(1,:) ;
i2 = matches(2,:) ;
else
i1 = [] ;
i2 = [] ;
end
f2p = f2 ;
f2p(1,:) = f2p(1,:) + o ;
if opts.plotAllFrames
vl_plotframe(f1,'linewidth',2) ;
vl_plotframe(f2p,'linewidth',2) ;
else
vl_plotframe(f1(:,i1),'linewidth',2) ;
vl_plotframe(f2p(:,i2),'linewidth',2) ;
end
line([f1(1,i1);f2p(1,i2)], [f1(2,i1);f2p(2,i2)]) ;
title(sprintf('number of matches: %d', size(matches,2))) ;
if ~isempty(opts.homography)
s.axes = gca ;
s.cursor1 = [0;0];
s.cursor2 = [0;0];
s.size1 = size(im1) ;
s.size2 = size(im2) ;
s.point1 = plot(0,0,'g+','MarkerSize', 40, 'EraseMode','xor') ;
s.point2 = plot(0,0,'r+','MarkerSize', 40, 'EraseMode','xor') ;
s.H = inv(opts.homography) ;
set(gcf, 'UserData', s)
set(gcf, 'WindowButtonMotionFcn', @mouseMove) ;
end
function mouseMove(object, eventData)
s = get(object, 'UserData') ;
point = get(s.axes, 'CurrentPoint') ;
if point(1) <= s.size1(2)
s.cursor1 = point(1, 1:2)' ;
z = s.H * [s.cursor1;1] ;
s.cursor2 = z(1:2) / z(3) ;
else
s.cursor2 = point(1, 1:2)' - [s.size1(2) ; 0] ;
z = inv(s.H) * [s.cursor2;1] ;
s.cursor1 = z(1:2) / z(3) ;
end
set(s.point1, 'XData', s.cursor1(1) , 'YData', s.cursor1(2)) ;
set(s.point2, 'XData', s.cursor2(1) + s.size1(2) , 'YData', s.cursor2(2)) ;