-
Notifications
You must be signed in to change notification settings - Fork 0
/
find_transform.m
96 lines (78 loc) · 3.13 KB
/
find_transform.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
84
85
86
87
88
89
90
91
92
93
94
95
96
run ~/CVIT/vlfeat-0.9.20/toolbox/vl_setup.m
clear;
load('Frames1.mat');
load('Frames2.mat');
cnt = 1;
for i=1:399
disp(i);
[matches,score] = vl_ubcmatch(descriptor1{cnt},descriptor1{cnt+1});
im1_Points = feature1{1,cnt}(1:2,matches(1,:));
im2_Points = feature1{1,cnt+1}(1:2,matches(2,:));
%figure;
%showMatchedFeatures(images_frames2{cnt}, images_frames2{cnt+1},...
% im1_Points', im2_Points');
%legend('A', 'B');
[tform{cnt}, inside_im1_Points, inside_im2_Points] = ...
estimateGeometricTransform(im1_Points', im2_Points', 'similarity');
%imgA = imwarp(images_frames1{cnt}, tform{cnt}, 'OutputView',...
% imref2d(size(images_frames1{cnt})));
%new_inside_im1_Points = transformPointsForward(tform{cnt}, inside_im1_Points);
%figure;
%showMatchedFeatures(imgA, images_frames2{cnt+1},...
% new_inside_im1_Points, inside_im2_Points);
%legend('A', 'B');
H = tform{cnt}.T;
%{
R = H(1:2,1:2);
theta2{cnt} = mean([atan2(R(2),R(1)) atan2(-R(3),R(4))]);
scale2{cnt} = mean(R([1 4])/cos(theta2{cnt}));
translation2{cnt} = H(3, 1:2);
%}
scale1{cnt} = sqrt(H(1,1).^2 + H(2,1).^2);
theta1{cnt} = atan2(H(2,1),H(1,1));
translation1{cnt} = H(3,1:2);
%HsRt = [[scale1{cnt}*[cos(theta1{cnt}) -sin(theta1{cnt}); sin(theta1{cnt}) cos(theta1{cnt})]; ...
% translation1{cnt}], [0 0 1]'];
%HsRt = [[scale1{cnt}*[cos(theta1{cnt}) -sin(theta1{cnt}); sin(theta1{cnt}) cos(theta1{cnt})]; ...
% translation1{cnt}], [0 0 1]'];
F1{cnt} = tform{cnt};
cnt = cnt + 1;
end
%%% Below commented code should be used at points where we have breaked our
%%% frames (Eg:- Current split is at 400th frame)
%{
for i=400:400
disp(i);
[matches,score] = vl_ubcmatch(descriptor1{cnt},descriptor2{1});
im1_Points = feature1{1,cnt}(1:2,matches(1,:));
im2_Points = feature2{1,1}(1:2,matches(2,:));
%figure;
%showMatchedFeatures(images_frames1{cnt}, images_frames1{cnt+1},...
% im1_Points', im2_Points');
%legend('A', 'B');
[tform{cnt}, inside_im1_Points, inside_im2_Points] = ...
estimateGeometricTransform(im1_Points', im2_Points', 'similarity');
%imgBp = imwarp(images_frames2{1}, tform{cnt}, 'OutputView',...
% imref2d(size(images_frames2{1})));
%new_inside_im2_Points = transformPointsForward(tform{cnt}, inside_im2_Points);
%figure;
%showMatchedFeatures(images_frames1{cnt}, images_frames1{cnt+1},...
% inside_im1_Points, new_inside_im2_Points);
%legend('A', 'B');
H = tform{cnt}.T;
%{
R = H(1:2,1:2);
theta1{cnt} = mean([atan2(R(2),R(1)) atan2(-R(3),R(4))]);
scale1{cnt} = mean(R([1 4])/cos(theta1{cnt}));
translation1{cnt} = H(3, 1:2);
%}
scale1{cnt} = sqrt(H(1,1).^2 + H(1,2).^2);
theta1{cnt} = atan2(H(2,1),H(1,1));
translation1{cnt} = H(3,1:2);
%HsRt = [[scale1{cnt}*[cos(theta1{cnt}) -sin(theta1{cnt}); sin(theta1{cnt}) cos(theta1{cnt})]; ...
% translation1{cnt}], [0 0 1]'];
F1{cnt} = tform{cnt};
cnt = cnt + 1;
end
%}
save('Transform1.mat','F1','theta1','scale1','translation1');