From d17b33131c14864bd1eae275f49a3f148e21cf29 Mon Sep 17 00:00:00 2001 From: Leo Chan Date: Thu, 22 Oct 2020 01:53:21 -0400 Subject: Squashed commit of the sb-vbs branch. Includes the SD-VBS benchmarks modified to: - Use libextra to loop as realtime jobs - Preallocate memory before starting their main computation - Accept input via stdin instead of via argc Does not include the SD-VBS matlab code. Fixes libextra execution in LITMUS^RT. --- SD-VBS/common/toolbox/toolbox_basic/fact/factor.m | 50 +++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100755 SD-VBS/common/toolbox/toolbox_basic/fact/factor.m (limited to 'SD-VBS/common/toolbox/toolbox_basic/fact/factor.m') diff --git a/SD-VBS/common/toolbox/toolbox_basic/fact/factor.m b/SD-VBS/common/toolbox/toolbox_basic/fact/factor.m new file mode 100755 index 0000000..635c29a --- /dev/null +++ b/SD-VBS/common/toolbox/toolbox_basic/fact/factor.m @@ -0,0 +1,50 @@ +% +% Usage: +% +% [R,t,S] = factor(W) +% +% Function to factor a matrix of input data (W) into the camera +% rotation matrix (R), translation (t), and the shape matrix (S). +% Three-dimensional version. Failure of normalization results in +% empty R and S. + +function [R,t,S] = factor(W) + +pts = size(W,2); +t = W*ones(pts,1)/pts; +W = W - t*ones(1,pts); + +% Use SVD to factor W. + [a,b,c] = svd(W,0); + +smallb = b(1:3,1:3); % Since W is rank 3, b has only three meaningful values +sqrtb = sqrt(smallb); +Rhat = a(:,1:3) * sqrtb; +Shat = sqrtb * c(:,1:3)'; + +G = findG(Rhat); + +if size(G,1) == 0, +R = []; +S = []; +else + R = Rhat*G; + S = inv(G)*Shat; + + % rotation matrix that aligns the reference frame with the first camera + F = size(R,1)/2; + R1 = R(1,:); + R1 = R1/norm(R1); + R2 = R(F+1,:); + R2 = R2/norm(R2); + R3 = cross(R1,R2); + R3 = R3/norm(R3); + P = [R1; R2; R3]; + P = P'; + + R = R*P; + S = inv(P)*S; +end + + + -- cgit v1.2.2