-
Notifications
You must be signed in to change notification settings - Fork 23
/
hand_fitting.m
52 lines (43 loc) · 1.48 KB
/
hand_fitting.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
function hand_fitting()
addpath(genpath('..'))
% loading the image and creating mask to discard pixels we don't want to us
% in the loss
hand_image=double(imread('hand.png'))/255;
mask=conv2(max(hand_image,[],3)>=1 ,ones(3,3) ,'same')==0;
% fixing hand color and backround color
background_color=[0.5,0.6,.7]';
hand_color=[0.4,0.3,0.25]';
% loading the hand 3D mesh
objfile='hand.obj';
h=loadawobj(objfile);
faces = flipud(h.f3);% reorient face
vertices = h.v;
vertices_colors = hand_color*ones(1,size(vertices,2));
% choosing the position of the camera so that the we get a good
% initialization for the fitter
width=size(hand_image,2);
height=size(hand_image,1);
object_center=mean(vertices,2);
objectRadius=max(std(vertices,1,2));
camera_center=object_center+[0,0,9]'*objectRadius;
focal=2*width;
R=[1,0,0;0,-1,0;0,0,-1];
T=-R'*camera_center;
CameraMatrix=[focal,0,width/2;0,focal,height/2;0,0,1]*[R,T];
lights.light_directional=1*[0.1,0.5,0.4];
lights.light_ambient=0.6;
options.sigma = 1;% edge antialising width
options.save_images = true;
options.display = 1;
options.antialiaseError = 0;
options.gamma = 0.01;
options.alpha = 0.0;
options.beta = 0.01;
options.inertia = 0.95;
options.damping = 0.2;
options.method = 'heavyBall';
options.nb_max_iter = 100;
options.iter_images_folder='iterations';
options.save_gif = true;
options.cregu=1000; % mesh rigidity regularisation coefficient
mesh_fitting(hand_image, mask, vertices, faces,vertices_colors, background_color,lights,CameraMatrix,options)