-
Notifications
You must be signed in to change notification settings - Fork 0
/
computeBox3D.m
39 lines (32 loc) · 1.19 KB
/
computeBox3D.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
function [corners_2D,face_idx] = computeBox3D(object,P)
% takes an object and a projection matrix (P) and projects the 3D
% bounding box into the image plane.
% index for 3D bounding box faces
face_idx = [ 1,2,6,5 % front face
2,3,7,6 % left face
3,4,8,7 % back face
4,1,5,8]; % right face
% compute rotational matrix around yaw axis
R = [+cos(object.ry), 0, +sin(object.ry);
0, 1, 0;
-sin(object.ry), 0, +cos(object.ry)];
% 3D bounding box dimensions
l = object.l;
w = object.w;
h = object.h;
% 3D bounding box corners
x_corners = [l/2, l/2, -l/2, -l/2, l/2, l/2, -l/2, -l/2];
y_corners = [0,0,0,0,-h,-h,-h,-h];
z_corners = [w/2, -w/2, -w/2, w/2, w/2, -w/2, -w/2, w/2];
% rotate and translate 3D bounding box
corners_3D = R*[x_corners;y_corners;z_corners];
corners_3D(1,:) = corners_3D(1,:) + object.t(1);
corners_3D(2,:) = corners_3D(2,:) + object.t(2);
corners_3D(3,:) = corners_3D(3,:) + object.t(3);
% only draw 3D bounding box for objects in front of the camera
if any(corners_3D(3,:)<0.1)
corners_2D = [];
return;
end
% project the 3D bounding box into the image plane
corners_2D = projectToImage(corners_3D, P);