-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_proj2metric_square.m
38 lines (32 loc) · 1.15 KB
/
test_proj2metric_square.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
function test_proj2metric_square(filename)
timestamp = strftime("%Y%m%d-%H%M", localtime(time()));
funcname = substr(mfilename(), 6);
prefix = sprintf("%s_%s_%s", filename, funcname, timestamp);
I = imread(filename);
img = I;
if (isrgb(img))
img = rgb2gray(img);
endif
fullscreen = get(0,'ScreenSize');
fig = figure('Position',[0 -50 fullscreen(3) fullscreen(4)]);
clf;
imshow(img);
hold on;
title("Click 4 points that make a square in the real world, in order:");
coords = capture_quad();
title("Original Image");
plot_vanishing_line([coords coords(:,1)]);
print(fig, "-dpng", sprintf("%s_original.png", prefix));
close(fig);
T = proj2metric_square(coords);
I_T = imperspectivewarp(I, T, "bilinear", "loose");
fig = figure('Position',[0 -50 fullscreen(3) fullscreen(4)]);
imshow(rgb2gray(I_T));
hold on;
title("Rectified Image");
coords = T*coords;
plot_vanishing_line([coords coords(:,1)]);
print(fig, "-dpng", sprintf("%s_rectified.png", prefix));
close(fig);
imwrite(I_T, sprintf("%s_.png", prefix));
endfunction