-
Notifications
You must be signed in to change notification settings - Fork 93
/
compute3dOcc_eval.m
162 lines (135 loc) · 4.92 KB
/
compute3dOcc_eval.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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
function score = compute3dOcc_eval(gt, cor_id, im_h, im_w);
% compute 3d IoU between gt corner position and
% predicted corner posision in 2D
addpath(genpath('./mesh2voxel/'));
c_h = 1.7;
voxelScale = 200;
% gen box gt
cor_a_x = cor_id(2,1) - im_w/2;
cor_a_y = (im_h - cor_id(2,2))-im_h/2;
cor_a_y_ = (im_h - cor_id(1,2))-im_h/2;
theta_x = 2*pi*cor_a_x/im_w;
theta_y = pi*cor_a_y/im_h;
theta_y_ = pi*cor_a_y_/im_h;
r = abs(cot(theta_y))*c_h;
cor_a_X = r*cos(-theta_x+pi/2);% *ch
cor_a_Z = r*sin(-theta_x+pi/2);% *ch
cor_a_Y_ = r*tan(theta_y_)+c_h;
cor_b_x = cor_id(4,1) - im_w/2;
cor_b_y = (im_h - cor_id(4,2))-im_h/2;
cor_b_y_ = (im_h - cor_id(3,2))-im_h/2;
theta_x = 2*pi*cor_b_x/im_w;
theta_y = pi*cor_b_y/im_h;
theta_y_ = pi*cor_b_y_/im_h;
r = abs(cot(theta_y))*c_h;
cor_b_X = r*cos(-theta_x+pi/2);% *ch
cor_b_Z = r*sin(-theta_x+pi/2);% *ch
cor_b_Y_ = r*tan(theta_y_) +c_h;
cor_c_x = cor_id(6,1) - im_w/2;
cor_c_y = (im_h - cor_id(6,2))-im_h/2;
cor_c_y_ = (im_h - cor_id(5,2))-im_h/2;
theta_x = 2*pi*cor_c_x/im_w;
theta_y = pi*cor_c_y/im_h;
theta_y_ = pi*cor_c_y_/im_h;
r = abs(cot(theta_y))*c_h;
cor_c_X = r*cos(-theta_x+pi/2);% *ch
cor_c_Z = r*sin(-theta_x+pi/2);% *ch
cor_c_Y_ = r*tan(theta_y_) +c_h;
cor_d_x = cor_id(8,1) - im_w/2;
cor_d_y = (im_h - cor_id(8,2))-im_h/2;
cor_d_y_ = (im_h - cor_id(7,2))-im_h/2;
theta_x = 2*pi*cor_d_x/im_w;
theta_y = pi*cor_d_y/im_h;
theta_y_ = pi*cor_d_y_/im_h;
r = abs(cot(theta_y))*c_h;
cor_d_X = r*cos(-theta_x+pi/2);% *ch
cor_d_Z = r*sin(-theta_x+pi/2);% *ch
cor_d_Y_ = r*tan(theta_y_) +c_h;
% check correctness
cor_a = [cor_a_X, 0, cor_a_Z];
cor_b = [cor_b_X, 0, cor_b_Z];
cor_c = [cor_c_X, 0, cor_c_Z];
cor_d = [cor_d_X, 0, cor_d_Z];
cor_a_h = [cor_a_X, cor_a_Y_, cor_a_Z];
cor_b_h = [cor_b_X, cor_b_Y_, cor_b_Z];
cor_c_h = [cor_c_X, cor_c_Y_, cor_c_Z];
cor_d_h = [cor_d_X, cor_d_Y_, cor_d_Z];
% gt part
% gen box gt
gt_a_x = gt(2,1) - im_w/2;
gt_a_y = (im_h - gt(2,2))-im_h/2;
gt_a_y_ = (im_h - gt(1,2))-im_h/2;
theta_x = 2*pi*gt_a_x/im_w;
theta_y = pi*gt_a_y/im_h;
theta_y_ = pi*gt_a_y_/im_h;
r = abs(cot(theta_y))*c_h;
gt_a_X = r*cos(-theta_x+pi/2);% *ch
gt_a_Z = r*sin(-theta_x+pi/2);% *ch
gt_a_Y_ = r*tan(theta_y_)+c_h;
gt_b_x = gt(4,1) - im_w/2;
gt_b_y = (im_h - gt(4,2))-im_h/2;
gt_b_y_ = (im_h - gt(3,2))-im_h/2;
theta_x = 2*pi*gt_b_x/im_w;
theta_y = pi*gt_b_y/im_h;
theta_y_ = pi*gt_b_y_/im_h;
r = abs(cot(theta_y))*c_h;
gt_b_X = r*cos(-theta_x+pi/2);% *ch
gt_b_Z = r*sin(-theta_x+pi/2);% *ch
gt_b_Y_ = r*tan(theta_y_) +c_h;
gt_c_x = gt(6,1) - im_w/2;
gt_c_y = (im_h - gt(6,2))-im_h/2;
gt_c_y_ = (im_h - gt(5,2))-im_h/2;
theta_x = 2*pi*gt_c_x/im_w;
theta_y = pi*gt_c_y/im_h;
theta_y_ = pi*gt_c_y_/im_h;
r = abs(cot(theta_y))*c_h;
gt_c_X = r*cos(-theta_x+pi/2);% *ch
gt_c_Z = r*sin(-theta_x+pi/2);% *ch
gt_c_Y_ = r*tan(theta_y_) +c_h;
gt_d_x = gt(8,1) - im_w/2;
gt_d_y = (im_h - gt(8,2))-im_h/2;
gt_d_y_ = (im_h - gt(7,2))-im_h/2;
theta_x = 2*pi*gt_d_x/im_w;
theta_y = pi*gt_d_y/im_h;
theta_y_ = pi*gt_d_y_/im_h;
r = abs(cot(theta_y))*c_h;
gt_d_X = r*cos(-theta_x+pi/2);% *ch
gt_d_Z = r*sin(-theta_x+pi/2);% *ch
gt_d_Y_ = r*tan(theta_y_) +c_h;
gt_a = [gt_a_X, 0, gt_a_Z];
gt_b = [gt_b_X, 0, gt_b_Z];
gt_c = [gt_c_X, 0, gt_c_Z];
gt_d = [gt_d_X, 0, gt_d_Z];
gt_a_h = [gt_a_X, gt_a_Y_, gt_a_Z];
gt_b_h = [gt_b_X, gt_b_Y_, gt_b_Z];
gt_c_h = [gt_c_X, gt_c_Y_, gt_c_Z];
gt_d_h = [gt_d_X, gt_d_Y_, gt_d_Z];
% box
fvc.vertices = [cor_a; cor_b; cor_c; cor_d;cor_a_h; cor_b_h;cor_c_h;cor_d_h];
fvc.faces = [1 2 3; 1 3 4;
5 6 7; 5 7 8;
1 2 5; 2 5 7;
3 4 8; 3 8 7;
2 3 7; 2 7 6;
1 4 5; 4 5 8];
% gt
fvc_gt.vertices = [gt_a; gt_b; gt_c; gt_d;gt_a_h; gt_b_h;gt_c_h;gt_d_h];
fvc_gt.faces = [1 2 3; 1 3 4;
5 6 7; 5 7 8;
1 2 5; 2 5 7;
3 4 8; 3 8 7;
2 3 7; 2 7 6;
1 4 5; 4 5 8];
fmax = max([fvc.vertices; fvc_gt.vertices]);
fmin = min([fvc.vertices; fvc_gt.vertices]);
dist = pdist2([fvc.vertices; fvc_gt.vertices], [fvc.vertices; fvc_gt.vertices]);
[dist,~] = max(dist(:));
dist = sqrt(dist) * 1.1;
fvc.vertices = bsxfun(@minus, fvc.vertices,(fmax+fmin)/2);
fvc.vertices = fvc.vertices*voxelScale/dist;
pred_vox = polygon2voxel(fvc, [1 1 1]*voxelScale, 'center');
fvc_gt.vertices = bsxfun(@minus, fvc_gt.vertices,(fmax+fmin)/2);
fvc_gt.vertices = fvc_gt.vertices*voxelScale/dist;
gt_vox = polygon2voxel(fvc_gt, [1 1 1]*voxelScale, 'center');
[ score ] = VoxelIOUScore( pred_vox, gt_vox );
end