forked from panji530/Maximizing-rigidity-revisited
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_Tshirt.m
88 lines (73 loc) · 6.16 KB
/
test_Tshirt.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
% Script to run our NRSfM on the T-Shirt sequence
clear;
close all;
load tshirtdata; % obtained from Chhatkuli et al. data.
totframes = length(scene.m); % number of images
X = [];
Xgth = [];
for k = 1: totframes
X = [X;scene.m(k).m(1:2,:)];
Xgth = [Xgth;scene.Pgth(k).P];
end
idx = isnan(sum(Xgth));
X = X(:,~idx);
Xgth = Xgth(:,~idx);
xmin = min(vec(Xgth(1:3:end,:)));
xmax = max(vec(Xgth(1:3:end,:)));
ymin = min(vec(Xgth(2:3:end,:)));
ymax = max(vec(Xgth(2:3:end,:)));
zmin = min(vec(Xgth(3:3:end,:)));
zmax = max(vec(Xgth(3:3:end,:)));
for k = 1: totframes
m(k).m = X((2*k-1):(2*k),:);
Pgt(k).P = Xgth((3*k-2):(3*k),:);
end
N = length(m(1).m);
M = length(m);
% visibility is true for the example:
visibt = true(N,M);
Kneighbors = 20;
[IDX, dist_sort] = getNeighborsVis(m,Kneighbors,visibt);
visbc = num2cell(visibt,1);
C = getAngleCos(m,IDX);
lambda1 = 1;
lambda2 = 20;
% second part: formulate SDP and solve with CVX
mc = squeeze(struct2cell(m));
disp('NRSfM function');
tic;
[mu,D] = OurNRSfM(IDX,C, m, lambda1,lambda2);
ts = toc;
% third part: display results,
%%
res.Q2 = cell(1,M);
res.Pg = cell(1,M);
res.err3d = zeros(1,M); % RMSE for each surface
res.err3dper = zeros(1,M); % RMSE for each surface
for k=1:M
Q2k=double([mu(k,visibt(:,k));mu(k,visibt(:,k));mu(k,visibt(:,k))]).*[m(k).m(:,visibt(:,k));ones(1,length(m(k).m(:,visibt(:,k))))];
P2 = Pgt(k).P(:,visibt(:,k));
% get valid indices: some groundtruth points are 0
mugth = P2(3,:);
l = mugth>0;
% fix scale of reconstructed surface
Q2k_n = RegisterToGTH(Q2k(:,l),P2(:,l));
figure(1)
clf;
plot3(Q2k_n(1,:),Q2k_n(2,:),Q2k_n(3,:),'b*');
axis equal
axis([xmin xmax ymin ymax zmin zmax])
hold on;
plot3(P2(1,l),P2(2,l),P2(3,l),'go');
hold off;
pause(0.1);
res.Q2{k} = Q2k_n;
res.Pg{k} = P2(:,l);
scale = norm(P2(:,l),'fro');
res.err3dper(k) = norm(Q2k_n - P2(:,l),'fro')/scale*100;
res.err3d(k) = sqrt(mean(sum((P2(:,l)-Q2k_n).^2)));
fprintf('3D rmse =%.2f mm\t',res.err3d(k));
fprintf('relative 3D error =%.2f %% \n',res.err3dper(k));
end
meandepth = mean(res.err3d)
meanper = mean(res.err3dper)