1 | function fig=vgg_gui_H(i1,i2,H)
|
---|
2 | %
|
---|
3 | % fig=vgg_gui_H(i1,i2,H)
|
---|
4 | %
|
---|
5 | %
|
---|
6 | % Visualizes an homography matrix of two views
|
---|
7 | %
|
---|
8 | %IN:
|
---|
9 | % i1 - Matlab image
|
---|
10 | % i2 - Matlab image
|
---|
11 | % H - 3x3 Homography matrix. Assumes that image coordiantes are 1..width
|
---|
12 | % where pixel centers are at integer locations.
|
---|
13 | %
|
---|
14 | %OUT:
|
---|
15 | % fig - handle to the figure
|
---|
16 |
|
---|
17 | % $Id: vgg_gui_H.m,v 1.3 2001/10/30 14:42:41 wexler Exp $
|
---|
18 | % Yoni, Tue Mar 27 19:31:16 2001
|
---|
19 |
|
---|
20 |
|
---|
21 | if nargin==3
|
---|
22 | action='start';
|
---|
23 | else
|
---|
24 | action=i1;
|
---|
25 | ud = get(gcf, 'UserData');
|
---|
26 | end
|
---|
27 |
|
---|
28 | if strcmp(action,'start'),
|
---|
29 | if nargin ~= 3
|
---|
30 | error('Must give 3 arguments... read the docs.\n');
|
---|
31 | end
|
---|
32 |
|
---|
33 | h0 = figure('Color',[0.8 0.8 0.8], ...
|
---|
34 | 'NumberTitle','off', ...
|
---|
35 | 'Name','Play With Homography Matrix', ...
|
---|
36 | 'ButtonDownFcn', 'disp(''Click on images'')',...
|
---|
37 | 'WindowButtonUpFcn', 'vgg_gui_H(''none'');',...
|
---|
38 | 'WindowButtonMotionFcn', 'vgg_gui_H(''move'')', ...
|
---|
39 | 'Pointer', 'crosshair', ...
|
---|
40 | 'DoubleBuffer', 'on',...
|
---|
41 | 'Units','normalized');
|
---|
42 | m0=uimenu('Label', '&Color');
|
---|
43 | uimenu(m0, 'Label', '&Red', 'ForegroundColor', [1 0 0], ...
|
---|
44 | 'Accelerator', 'r', 'Callback', 'vgg_gui_H(''cr'');');
|
---|
45 | uimenu(m0, 'Label', '&Green', 'ForegroundColor', [0 1 0], ...
|
---|
46 | 'Accelerator', 'g', 'Callback', 'vgg_gui_H(''cg'');');
|
---|
47 | uimenu(m0, 'Label', '&Blue', 'ForegroundColor', [0 0 1], ...
|
---|
48 | 'Accelerator', 'b', 'Callback', 'vgg_gui_H(''cb'');');
|
---|
49 | m1=uimenu('Label', '&Size');
|
---|
50 | uimenu(m1, 'Label', '&Increase', 'Callback', 'vgg_gui_H(''s+'');', 'Accelerator', '+');
|
---|
51 | uimenu(m1, 'Label', '&Decrease', 'Callback', 'vgg_gui_H(''s-'');', 'Accelerator', '-');
|
---|
52 | uimenu(m1, 'Label', '&1', 'Callback', 'vgg_gui_H(''s1'');', 'Accelerator', '1');
|
---|
53 | uimenu(m1, 'Label', '&2', 'Callback', 'vgg_gui_H(''s2'');', 'Accelerator', '2');
|
---|
54 | uimenu(m1, 'Label', '&3', 'Callback', 'vgg_gui_H(''s3'');', 'Accelerator', '3');
|
---|
55 | uimenu(m1, 'Label', '&4', 'Callback', 'vgg_gui_H(''s4'');', 'Accelerator', '4');
|
---|
56 | uimenu(m1, 'Label', '&5', 'Callback', 'vgg_gui_H(''s5'');', 'Accelerator', '5');
|
---|
57 | uimenu(m1, 'Label', '&6', 'Callback', 'vgg_gui_H(''s6'');', 'Accelerator', '6');
|
---|
58 | uimenu(m1, 'Label', '&7', 'Callback', 'vgg_gui_H(''s7'');', 'Accelerator', '7');
|
---|
59 | uimenu(m1, 'Label', '&8', 'Callback', 'vgg_gui_H(''s8'');', 'Accelerator', '8');
|
---|
60 | uimenu(m1, 'Label', '&9', 'Callback', 'vgg_gui_H(''s9'');', 'Accelerator', '9');
|
---|
61 |
|
---|
62 | ah1 = axes('Parent', h0, ...
|
---|
63 | 'Position',[0 0 .5 1]);
|
---|
64 | h1=imshow(i1); hold on; title('Image 1');
|
---|
65 | set(h1, 'ButtonDownFcn','vgg_gui_H(''b1'');');
|
---|
66 |
|
---|
67 | ah2 = axes('Parent',h0, ...
|
---|
68 | 'Position',[.5 0 .5 1], ...
|
---|
69 | 'Tag','Axes2');
|
---|
70 | h2=imshow(i2); hold on; title('Image 2');
|
---|
71 | set(h2, 'ButtonDownFcn','vgg_gui_H(''b2'');');
|
---|
72 |
|
---|
73 | point=plot(-1000, -1000,'EraseMode','xor');
|
---|
74 | point2=plot(-1000, -1000,'EraseMode','xor');
|
---|
75 |
|
---|
76 | s1=size(i1); s2=size(i2);
|
---|
77 | t(:,:,1)=H; t(:,:,2)=inv(H); H=t;
|
---|
78 |
|
---|
79 | ud=struct('h0', h0, 'h',[h1 h2], 'ah', [ah1, ah2], ...
|
---|
80 | 'sizes', [s1(1:2); s2(1:2)], ...
|
---|
81 | 'current', -1, 'color', 'r', 'size', 1, ...
|
---|
82 | 'p', point, 'H', H, 'p2', point2 );
|
---|
83 |
|
---|
84 | set(h0,'UserData',ud);
|
---|
85 |
|
---|
86 | if nargout > 0, fig = h0; end
|
---|
87 |
|
---|
88 | elseif strcmp(action, 'move')
|
---|
89 | if ud.current<0 return; end;
|
---|
90 | pt=get(ud.ah(ud.current),'CurrentPoint');
|
---|
91 | pt2=ud.H(:,:,ud.current)*pt(1,:)';
|
---|
92 | pt2=pt2/pt2(3);
|
---|
93 |
|
---|
94 | set(ud.p2, 'XData', pt2(1,1), 'YData', pt2(2,1))
|
---|
95 | set(ud.p, 'XData', pt(1,1), 'YData', pt(1,2))
|
---|
96 |
|
---|
97 | elseif action(1)=='b'
|
---|
98 | if action(2)=='1' ud.current=1;
|
---|
99 | elseif action(2)=='2' ud.current=2;
|
---|
100 | else return;
|
---|
101 | end
|
---|
102 | pt=get(ud.ah(ud.current),'CurrentPoint');
|
---|
103 |
|
---|
104 | p2=ud.H(:,:,ud.current)*pt(1,:)';
|
---|
105 | p2=p2/p2(3);
|
---|
106 |
|
---|
107 | delete(ud.p);
|
---|
108 | delete(ud.p2);
|
---|
109 | axes(ud.ah(ud.current));
|
---|
110 | ud.p=plot(pt(1,1), pt(1,2), [ud.color '+'], ...
|
---|
111 | 'MarkerSize', 8+2*ud.size, 'LineWidth', ud.size,...
|
---|
112 | 'EraseMode','xor');
|
---|
113 | axes(ud.ah(3-ud.current));
|
---|
114 | ud.p2=plot(p2(1,1), p2(2,1), [ud.color '+'], ...
|
---|
115 | 'MarkerSize', 8+2*ud.size, 'LineWidth', ud.size,...
|
---|
116 | 'EraseMode','xor');
|
---|
117 |
|
---|
118 | elseif action(1)=='c'
|
---|
119 | ud.color=action(2);
|
---|
120 | %get(ud.l)
|
---|
121 | set(ud.p2, 'Color', ud.color);
|
---|
122 | set(ud.p, 'Color', ud.color);
|
---|
123 |
|
---|
124 | elseif action(1)=='s'
|
---|
125 | if action(2)=='+' ud.size=ud.size+1;
|
---|
126 | elseif action(2)=='-' ud.size=max(1, ud.size-1);
|
---|
127 | else
|
---|
128 | ud.size = str2num(action(2));
|
---|
129 | end
|
---|
130 | set(ud.p, 'LineWidth', ud.size, 'MarkerSize', 8+2*ud.size);
|
---|
131 | set(ud.p2, 'LineWidth', ud.size, 'MarkerSize', 8+2*ud.size);
|
---|
132 |
|
---|
133 | elseif strcmp(action, 'none')
|
---|
134 | ud.current = -1;
|
---|
135 |
|
---|
136 | else
|
---|
137 | error(['Unknown command: ' action]);
|
---|
138 | end
|
---|
139 |
|
---|
140 | set(ud.h0, 'UserData',ud);
|
---|
141 |
|
---|