-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
update the utility folder to correct one
- Loading branch information
JeffsanC
committed
Mar 7, 2018
1 parent
b18e176
commit 6857dd2
Showing
5 changed files
with
252 additions
and
225 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,62 @@ | ||
function q = affparam2geom(p) | ||
% function q = affparam2geom(p) | ||
% | ||
% The functions affparam2geom and affparam2mat convert a 'geometric' | ||
% affine parameter to/from a matrix form (2x3 matrix). | ||
% | ||
% affparam2geom converts a 2x3 matrix to 6 affine parameters | ||
% (x, y, th, scale, aspect, skew), and affparam2mat does the inverse. | ||
% | ||
% p(6) : [p(1) p(3) p(4); p(2) p(5) p(6)] | ||
% q(6) : [dx dy sc th sr phi] | ||
% | ||
% Reference "Multiple View Geometry in Computer Vision" by Richard | ||
% Hartley and Andrew Zisserman. | ||
|
||
% Copyright (C) Jongwoo Lim and David Ross. All rights reserved. | ||
|
||
A = [ p(3), p(4); p(5), p(6) ]; | ||
%% A = USVt = (UVt)(VSVt) = R(th)R(-phi)SR(phi) | ||
[U,S,V] = svd(A); | ||
if (det(U) < 0) | ||
U = U(:,2:-1:1); V = V(:,2:-1:1); S = S(2:-1:1,2:-1:1); | ||
end | ||
q(1) = p(1); q(2) = p(2); | ||
q(4) = atan2(U(2,1)*V(1,1)+U(2,2)*V(1,2), U(1,1)*V(1,1)+U(1,2)*V(1,2)); | ||
|
||
phi = atan2(V(1,2),V(1,1)); | ||
if (phi <= -pi/2) | ||
c = cos(-pi/2); s = sin(-pi/2); | ||
R = [c -s; s c]; V = V * R; S = R'*S*R; | ||
end | ||
if (phi >= pi/2) | ||
c = cos(pi/2); s = sin(pi/2); | ||
R = [c -s; s c]; V = V * R; S = R'*S*R; | ||
end | ||
q(3) = S(1,1); | ||
q(5) = S(2,2)/S(1,1); | ||
q(6) = atan2(V(1,2),V(1,1)); | ||
q = reshape(q, size(p)); | ||
function q = affparam2geom(p) | ||
% function q = affparam2geom(p) | ||
% | ||
% 输入 : p,原始参数矩阵; | ||
% 输出 : q,具有几何意义的参数; | ||
% The functions affparam2geom and affparam2mat convert a 'geometric' | ||
% affine parameter to/from a matrix form (2x3 matrix). | ||
% | ||
% affparam2geom converts a 2x3 matrix to 6 affine parameters | ||
% (x, y, th, scale, aspect, skew), and affparam2mat does the inverse. | ||
% | ||
% p(6) : [p(1) p(3) p(4); p(2) p(5) p(6)] | ||
% | ||
% x' p(3) p(4) p(1) x | ||
% y' = p(5) p(6) p(2) * y | ||
% 1 0 0 1 1 | ||
% | ||
% p(3) p(4) | ||
% A = | ||
% p(5) p(6) | ||
% | ||
% q(6) : [dx dy sc th sr phi] | ||
% dx,dy : 平移变换 | ||
% sc,sr : 尺度变换 | ||
% th : 旋转变换 | ||
% phi : 错切变换 | ||
% | ||
% Reference "Multiple View Geometry in Computer Vision" by Richard | ||
% Hartley and Andrew Zisserman. | ||
|
||
% Copyright (C) Jongwoo Lim and David Ross. All rights reserved. | ||
|
||
A = [ p(3), p(4); p(5), p(6) ]; | ||
%% A = USVt = (UVt)(VSVt) = R(th)R(-phi)SR(phi) | ||
[U,S,V] = svd(A); | ||
if (det(U) < 0) | ||
U = U(:,2:-1:1); V = V(:,2:-1:1); S = S(2:-1:1,2:-1:1); | ||
end | ||
%%*******平移变换*******%% | ||
q(1) = p(1); | ||
q(2) = p(2); | ||
%%*******平移变换*******%% | ||
|
||
q(4) = atan2(U(2,1)*V(1,1)+U(2,2)*V(1,2), U(1,1)*V(1,1)+U(1,2)*V(1,2)); | ||
|
||
phi = atan2(V(1,2),V(1,1)); | ||
if (phi <= -pi/2) | ||
c = cos(-pi/2); s = sin(-pi/2); | ||
R = [c -s; s c]; V = V * R; S = R'*S*R; | ||
end | ||
if (phi >= pi/2) | ||
c = cos(pi/2); s = sin(pi/2); | ||
R = [c -s; s c]; V = V * R; S = R'*S*R; | ||
end | ||
|
||
%%*******尺度变换*******%% | ||
q(3) = S(1,1); | ||
q(5) = S(2,2)/S(1,1); | ||
%%*******尺度变换*******%% | ||
q(6) = atan2(V(1,2),V(1,1)); | ||
|
||
q = reshape(q, size(p)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,33 @@ | ||
function q = affparam2mat(p) | ||
% function q = affparam2mat(p) | ||
% | ||
% The functions affparam2geom and affparam2mat convert a 'geometric' | ||
% affine parameter to/from a matrix form (2x3 matrix). | ||
% | ||
% affparam2geom converts a 2x3 matrix to 6 affine parameters | ||
% (x, y, th, scale, aspect, skew), and affparam2mat does the inverse. | ||
% | ||
% p(6,n) : [dx dy sc th sr phi]' | ||
% q(6,n) : [q(1) q(3) q(4); q(2) q(5) q(6)] | ||
% | ||
% Reference "Multiple View Geometry in Computer Vision" by Richard | ||
% Hartley and Andrew Zisserman. | ||
|
||
% Copyright (C) Jongwoo Lim and David Ross. All rights reserved. | ||
|
||
|
||
sz = size(p); | ||
if (length(p(:)) == 6) | ||
p = p(:); | ||
end | ||
s = p(3,:); th = p(4,:); r = p(5,:); phi = p(6,:); | ||
cth = cos(th); sth = sin(th); cph = cos(phi); sph = sin(phi); | ||
ccc = cth.*cph.*cph; ccs = cth.*cph.*sph; css = cth.*sph.*sph; | ||
scc = sth.*cph.*cph; scs = sth.*cph.*sph; sss = sth.*sph.*sph; | ||
q(1,:) = p(1,:); q(2,:) = p(2,:); | ||
q(3,:) = s.*(ccc +scs +r.*(css -scs)); q(4,:) = s.*(r.*(ccs -scc) -ccs -sss); | ||
q(5,:) = s.*(scc -ccs +r.*(ccs +sss)); q(6,:) = s.*(r.*(ccc +scs) -scs +css); | ||
q = reshape(q, sz); | ||
function q = affparam2mat(p) | ||
% function q = affparam2mat(p) | ||
% | ||
% The functions affparam2geom and affparam2mat convert a 'geometric' | ||
% affine parameter to/from a matrix form (2x3 matrix). | ||
% | ||
% 输入 : q,具有几何意义的参数; | ||
% 输出 : p,原始参数矩阵; | ||
% | ||
% affparam2geom converts a 2x3 matrix to 6 affine parameters | ||
% (x, y, th, scale, aspect, skew), and affparam2mat does the inverse. | ||
% | ||
% p(6,n) : [dx dy sc th sr phi]' | ||
% q(6,n) : [q(1) q(3) q(4); q(2) q(5) q(6)] | ||
% | ||
% Reference "Multiple View Geometry in Computer Vision" by Richard | ||
% Hartley and Andrew Zisserman. | ||
|
||
% Copyright (C) Jongwoo Lim and David Ross. All rights reserved. | ||
|
||
|
||
sz = size(p); | ||
if (length(p(:)) == 6) | ||
p = p(:); | ||
end | ||
s = p(3,:); th = p(4,:); r = p(5,:); phi = p(6,:); | ||
cth = cos(th); sth = sin(th); cph = cos(phi); sph = sin(phi); | ||
ccc = cth.*cph.*cph; ccs = cth.*cph.*sph; css = cth.*sph.*sph; | ||
scc = sth.*cph.*cph; scs = sth.*cph.*sph; sss = sth.*sph.*sph; | ||
q(1,:) = p(1,:); q(2,:) = p(2,:); | ||
q(3,:) = s.*(ccc +scs +r.*(css -scs)); q(4,:) = s.*(r.*(ccs -scc) -ccs -sss); | ||
q(5,:) = s.*(scc -ccs +r.*(ccs +sss)); q(6,:) = s.*(r.*(ccc +scs) -scs +css); | ||
q = reshape(q, sz); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,17 @@ | ||
function q = affparaminv(p,q) | ||
% function q = affparaminv(p[, q]) | ||
% | ||
% p(6,n) : [dx dy sc th sr phi]' | ||
% q(6,n) : [q(1) q(3) q(4); q(2) q(5) q(6)] | ||
|
||
% Copyright (C) Jongwoo Lim and David Ross. All rights reserved. | ||
|
||
if (length(p) == 6) | ||
p = p(:); | ||
end | ||
if (nargin > 1) | ||
q = inv([p(3) p(4); p(5) p(6)]) * [q(1)-p(1) q(3:4); q(2)-p(2) q(5:6)]; | ||
else | ||
q = inv([p(3) p(4); p(5) p(6)]) * [-p(1) 1 0; -p(2) 0 1]; | ||
end | ||
q = q([1,2,3,5,4,6]); | ||
function q = affparaminv(p,q) | ||
% function q = affparaminv(p[, q]) | ||
% | ||
% p(6,n) : [dx dy sc th sr phi]' | ||
% q(6,n) : [q(1) q(3) q(4); q(2) q(5) q(6)] | ||
|
||
% Copyright (C) Jongwoo Lim and David Ross. All rights reserved. | ||
|
||
if (length(p) == 6) | ||
p = p(:); | ||
end | ||
if (nargin > 1) | ||
q = inv([p(3) p(4); p(5) p(6)]) * [q(1)-p(1) q(3:4); q(2)-p(2) q(5:6)]; | ||
else | ||
q = inv([p(3) p(4); p(5) p(6)]) * [-p(1) 1 0; -p(2) 0 1]; | ||
end | ||
q = q([1,2,3,5,4,6]); |
Oops, something went wrong.