-
Notifications
You must be signed in to change notification settings - Fork 0
/
catchKeyPress.m
58 lines (51 loc) · 1.76 KB
/
catchKeyPress.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
function [offset] = catchKeyPress(mask, targetImage)
h = figure;
[x, y, ~] = size(mask);
shift = [0 0 0];
set(h,'KeyPressFcn',@KeyPressCb);
p=1;
while p
imshow(targetImage.*repmat(uint8(mask),[1,1,3]));
end
offset = shift;
close;
function KeyPressCb(~,evnt)
%fprintf('key pressed: %s\n',evnt.Key);
if strcmpi(evnt.Key,'leftarrow')
shift(2) = shift(2)-4;
mask = circshift(mask,[0 -4]);
%I = imread('./plate_side_3.jpg');
offset = shift;
imshow(targetImage.*repmat(uint8(mask),[1,1,3]));
elseif strcmpi(evnt.Key,'rightarrow')
shift(2) = shift(2)+4;
mask = circshift(mask,[0 4]);
offset = shift;
imshow(targetImage.*repmat(uint8(mask),[1,1,3]));
elseif strcmpi(evnt.Key,'uparrow')
shift(1) = shift(1)-4;
mask = circshift(mask,[-4 0]);
%I = imread('./plate_side_3.jpg');
offset = shift;
imshow(targetImage.*repmat(uint8(mask),[1,1,3]));
elseif strcmpi(evnt.Key,'downarrow')
shift(1) = shift(1)+4;
mask = circshift(mask,[4 0]);
offset = shift;
%I = imread('./plate_side_3.jpg');
imshow(targetImage.*repmat(uint8(mask),[1,1,3]));
elseif strcmpi(evnt.Key,'space')
%close targetImage;
p = 0;
elseif strcmpi(evnt.Key,'u')
%close targetImage;
%upscale_x = x/2;
%upscale_y = y/2;
shift(3) = shift(3) +1;
mask = imdilate(mask, true(11));
elseif strcmpi(evnt.Key,'d')
%close targetImage;
mask = imdilate(mask, true(0.5));
end
end
end