diff --git a/.gitignore b/.gitignore index 60996a5..5d328c7 100644 --- a/.gitignore +++ b/.gitignore @@ -20,3 +20,7 @@ matlab_runners/Feature Point Experiments/yt_features/ matlab_runners/Feature Point Experiments/yt_features_clm/ matlab_runners/Gaze Experiments/mpii_out/ build/ +Release/AU_predictors/ +Release/ +exe/Recording/recording/ +ipch/ diff --git a/matlab_version/demo/face_image_demo_eyes.m b/matlab_version/demo/face_image_demo_eyes.m index 40a3714..05bf43f 100644 --- a/matlab_version/demo/face_image_demo_eyes.m +++ b/matlab_version/demo/face_image_demo_eyes.m @@ -9,22 +9,30 @@ addpath('../CCNF/'); [clmParams, pdm] = Load_CLM_params_wild(); -[clmParams_eye, pdm_eye] = Load_CLM_params_eye(); - % An accurate CCNF (or CLNF) model % [patches] = Load_Patch_Experts( '../models/general/', 'ccnf_patches_*_general.mat', [], [], clmParams); % A simpler (but less accurate SVR) [patches] = Load_Patch_Experts( '../models/general/', 'svr_patches_*_general.mat', [], [], clmParams); -[patches_eye] = Load_Patch_Experts( 'C:\Users\Tadas\Dropbox\AAM\patch_experts_eyes\svr_training\trained/', 'svr_patches_*_synth.mat', [], [], clmParams); +% Loading eye PDM and patch experts +[clmParams_eye, pdm_right_eye, pdm_left_eye] = Load_CLM_params_eye_28(); +[patches_right_eye] = Load_Patch_Experts( '../models/hierarch/', 'ccnf_patches_*_synth_right_eye.mat', [], [], clmParams_eye); +[patches_left_eye] = Load_Patch_Experts( '../models/hierarch/', 'ccnf_patches_*_synth_left_eye.mat', [], [], clmParams_eye); +clmParams_eye.multi_modal_types = patches_right_eye(1).multi_modal_types; +right_eye_inds = [43,44,45,46,47,48]; +left_eye_inds = [37,38,39,40,41,42]; + +right_eye_inds_synth = [9 11 13 15 17 19]; +left_eye_inds_synth = [9 11 13 15 17 19]; clmParams.multi_modal_types = patches(1).multi_modal_types; -clmParams_eye.multi_modal_types = patches_eye(1).multi_modal_types; - %% -root_dir = 'C:\Users\Tadas\Dropbox\AAM\test data\gaze_original\p00/'; -images = dir([root_dir, '*.jpg']); +% root_dir = 'C:\Users\Tadas\Dropbox\AAM\test data\gaze_original\p00/'; +% images = dir([root_dir, '*.jpg']); + +root_dir = './sample_eye_imgs/'; +images = dir([root_dir, '/*.png']); verbose = true; @@ -83,43 +91,36 @@ for img=1:numel(images) % shape correction for matlab format shape = shape + 1; + + % Perform eye fitting now + shape_r_eye = zeros(numel(pdm_right_eye.M)/3, 2); + shape_r_eye(right_eye_inds_synth,:) = shape(right_eye_inds, :); - if(verbose) + [ a, R, T, ~, l_params] = fit_PDM_ortho_proj_to_2D(pdm_right_eye.M, pdm_right_eye.E, pdm_right_eye.V, shape_r_eye); - % valid points to draw (not to draw self-occluded ones) - v_points = logical(patches(1).visibilities(view_used,:)); + bbox = [min(shape_r_eye(:,1)), min(shape_r_eye(:,2)), max(shape_r_eye(:,1)), max(shape_r_eye(:,2))]; - try - - plot(shape(v_points,1), shape(v_points',2),'.r','MarkerSize',20); - plot(shape(v_points,1), shape(v_points',2),'.b','MarkerSize',10); - - catch warn - - end - end - - % Map from detected landmarks to eye params - shape_r_eye = zeros(20,2); - shape_r_eye([9,11,13,15,17,19],:) = shape([43,44,45,46,47,48], :); - - [ a, R, T, ~, params, err, shapeOrtho] = fit_PDM_ortho_proj_to_2D(pdm_eye.M, pdm_eye.E, pdm_eye.V, shape_r_eye); - g_param = [a; Rot2Euler(R)'; T]; - l_param = params; - % Use the initial global and local params for clm fitting in the image - patches_eye(1).visibilities(1:8) = 0; - patches_eye(2).visibilities(1:8) = 0; - patches_eye(3).visibilities(1:8) = 0; - [shape_eye,~,~,lhood,lmark_lhood,view_used] = Fitting_from_bb(image, [], bbox, pdm_eye, patches_eye, clmParams_eye, 'gparam', g_param, 'lparam', l_param); + [shape_r_eye] = Fitting_from_bb(image, [], bbox, pdm_right_eye, patches_right_eye, clmParams_eye, 'gparam', g_param, 'lparam', l_params); - plot(shape_eye(:,1), shape_eye(:,2), '.g', 'MarkerSize',15); -% % Now do the eyes -% min_x = shape(43,1); -% max_x = shape(43,1); -% bbox_eye = shape(43,1) - + % Perform eye fitting now + shape_l_eye = zeros(numel(pdm_right_eye.M)/3, 2); + shape_l_eye(left_eye_inds_synth,:) = shape(left_eye_inds, :); + + [ a, R, T, ~, l_params] = fit_PDM_ortho_proj_to_2D(pdm_left_eye.M, pdm_left_eye.E, pdm_left_eye.V, shape_l_eye); + + bbox = [min(shape_l_eye(:,1)), min(shape_l_eye(:,2)), max(shape_l_eye(:,1)), max(shape_l_eye(:,2))]; + + g_param = [a; Rot2Euler(R)'; T]; + + [shape_l_eye] = Fitting_from_bb(image, [], bbox, pdm_left_eye, patches_left_eye, clmParams_eye, 'gparam', g_param, 'lparam', l_params); + + plot(shape_l_eye(9:20,1), shape_l_eye(9:20,2), '.g', 'MarkerSize',15); + plot(shape_l_eye(1:8,1), shape_l_eye(1:8,2), '.b', 'MarkerSize',15); + + plot(shape_r_eye(9:20,1), shape_r_eye(9:20,2), '.g', 'MarkerSize',15); + plot(shape_r_eye(1:8,1), shape_r_eye(1:8,2), '.b', 'MarkerSize',15); end hold off; diff --git a/matlab_version/demo/sample_eye_imgs/image_0037.png b/matlab_version/demo/sample_eye_imgs/image_0037.png new file mode 100644 index 0000000..34721de Binary files /dev/null and b/matlab_version/demo/sample_eye_imgs/image_0037.png differ diff --git a/matlab_version/demo/sample_eye_imgs/image_0038.png b/matlab_version/demo/sample_eye_imgs/image_0038.png new file mode 100644 index 0000000..af58c18 Binary files /dev/null and b/matlab_version/demo/sample_eye_imgs/image_0038.png differ diff --git a/matlab_version/demo/sample_eye_imgs/image_0039.png b/matlab_version/demo/sample_eye_imgs/image_0039.png new file mode 100644 index 0000000..a665a2d Binary files /dev/null and b/matlab_version/demo/sample_eye_imgs/image_0039.png differ diff --git a/matlab_version/demo/sample_eye_imgs/image_0093.png b/matlab_version/demo/sample_eye_imgs/image_0093.png new file mode 100644 index 0000000..defd5e9 Binary files /dev/null and b/matlab_version/demo/sample_eye_imgs/image_0093.png differ diff --git a/matlab_version/experiments_in_the_wild/Script_PDM_eyes.m b/matlab_version/experiments_in_the_wild/Script_PDM_eyes.m deleted file mode 100644 index e83a29d..0000000 --- a/matlab_version/experiments_in_the_wild/Script_PDM_eyes.m +++ /dev/null @@ -1,80 +0,0 @@ -function Script_PDM_eyes() - -addpath('../PDM_helpers/'); -addpath('../fitting/normxcorr2_mex_ALL'); -addpath('../fitting/'); -addpath('../CCNF/'); -addpath('../models/'); - -% Replace this with the location of in 300 faces in the wild data -if(exist([getenv('USERPROFILE') '/Dropbox/AAM/test data/'], 'file')) - root_test_data = [getenv('USERPROFILE') '/Dropbox/AAM/test data/']; -else - root_test_data = 'F:/Dropbox/Dropbox/AAM/test data/'; -end - -[images, detections, labels] = Collect_wild_imgs(root_test_data); - -%% Fitting the model to the provided image - -% the default PDM to use -pdmLoc = ['../models/pdm/pdm_68_aligned_wild_eyes.mat']; - -load(pdmLoc); - -pdm = struct; -pdm.M = double(M); -pdm.E = double(E); -pdm.V = double(V); - -num_points = numel(M)/3; - -errors = zeros(numel(images),1); -shapes_all = zeros(size(labels,2),size(labels,3), size(labels,1)); -labels_all = zeros(size(labels,2),size(labels,3), size(labels,1)); -errors_normed = zeros(numel(images),1); - -errors_left_eye = zeros(numel(images),1); -errors_right_eye = zeros(numel(images),1); - -tic -for i=1:numel(images) - - image = imread(images(i).img); - image_orig = image; - - if(size(image,3) == 3) - image = rgb2gray(image); - end - - labels_curr = squeeze(labels(i,:,:)); - - [ a, R, T, ~, l_params, err, shapeOrtho] = fit_PDM_ortho_proj_to_2D(pdm.M, pdm.E, pdm.V, labels_curr); - - shape = shapeOrtho; - shapes_all(:,:,i) = shapeOrtho; - labels_all(:,:,i) = labels_curr; - - if(mod(i, 200)==0) - fprintf('%d done\n', i ); - end - - valid_points = sum(squeeze(labels(i,:,:)),2) > 0; - valid_points(1:17) = 0; - - actualShape = squeeze(labels(i,:,:)); - errors(i) = sqrt(mean(sum((actualShape(valid_points,:) - shape(valid_points,:)).^2,2))); - width = ((max(actualShape(valid_points,1)) - min(actualShape(valid_points,1)))+(max(actualShape(valid_points,2)) - min(actualShape(valid_points,2))))/2; - errors_normed(i) = errors(i)/width; - - errors_left_eye(i) = compute_error_point_to_line_left_eye(actualShape, shapeOrtho, [0]); - errors_right_eye(i) = compute_error_point_to_line_right_eye(actualShape, shapeOrtho, [0]); - - if(errors_normed(i) > 0.035 || errors_left_eye(i) > 0.035 || errors_right_eye(i) > 0.035) - imshow(image);hold on; plot(shape(:,1), shape(:,2), '.g'); hold off; - end -end - -save('Errors_PDM_eyes.mat', 'errors_normed', 'errors_left_eye', 'errors_right_eye'); - -end diff --git a/matlab_version/experiments_in_the_wild/Script_PDM_general.m b/matlab_version/experiments_in_the_wild/Script_PDM_general.m deleted file mode 100644 index fb52e2e..0000000 --- a/matlab_version/experiments_in_the_wild/Script_PDM_general.m +++ /dev/null @@ -1,80 +0,0 @@ -function Script_PDM_general() - -addpath('../PDM_helpers/'); -addpath('../fitting/normxcorr2_mex_ALL'); -addpath('../fitting/'); -addpath('../CCNF/'); -addpath('../models/'); - -% Replace this with the location of in 300 faces in the wild data -if(exist([getenv('USERPROFILE') '/Dropbox/AAM/test data/'], 'file')) - root_test_data = [getenv('USERPROFILE') '/Dropbox/AAM/test data/']; -else - root_test_data = 'F:/Dropbox/Dropbox/AAM/test data/'; -end - -[images, detections, labels] = Collect_wild_imgs(root_test_data); - -%% Fitting the model to the provided image - -% the default PDM to use -pdmLoc = ['../models/pdm/pdm_68_aligned_wild.mat']; - -load(pdmLoc); - -pdm = struct; -pdm.M = double(M); -pdm.E = double(E); -pdm.V = double(V); - -num_points = numel(M)/3; - -errors = zeros(numel(images),1); -shapes_all = zeros(size(labels,2),size(labels,3), size(labels,1)); -labels_all = zeros(size(labels,2),size(labels,3), size(labels,1)); -errors_normed = zeros(numel(images),1); - -errors_left_eye = zeros(numel(images),1); -errors_right_eye = zeros(numel(images),1); - -tic -for i=1:numel(images) - - image = imread(images(i).img); - image_orig = image; - - if(size(image,3) == 3) - image = rgb2gray(image); - end - - labels_curr = squeeze(labels(i,:,:)); - - [ a, R, T, ~, l_params, err, shapeOrtho] = fit_PDM_ortho_proj_to_2D(pdm.M, pdm.E, pdm.V, labels_curr); - - shape = shapeOrtho; - shapes_all(:,:,i) = shapeOrtho; - labels_all(:,:,i) = labels_curr; - - if(mod(i, 200)==0) - fprintf('%d done\n', i ); - end - - valid_points = sum(squeeze(labels(i,:,:)),2) > 0; - valid_points(1:17) = 0; - - actualShape = squeeze(labels(i,:,:)); - errors(i) = sqrt(mean(sum((actualShape(valid_points,:) - shape(valid_points,:)).^2,2))); - width = ((max(actualShape(valid_points,1)) - min(actualShape(valid_points,1)))+(max(actualShape(valid_points,2)) - min(actualShape(valid_points,2))))/2; - errors_normed(i) = errors(i)/width; - - errors_left_eye(i) = compute_error_point_to_line_left_eye(actualShape, shapeOrtho, [0]); - errors_right_eye(i) = compute_error_point_to_line_right_eye(actualShape, shapeOrtho, [0]); - - if(errors_normed(i) > 0.035 || errors_left_eye(i) > 0.035 || errors_right_eye(i) > 0.035) - imshow(image);hold on; plot(shape(:,1), shape(:,2), '.g'); hold off; - end -end - -save('Errors_PDM_basic.mat', 'errors_normed', 'errors_left_eye', 'errors_right_eye'); - -end diff --git a/matlab_version/experiments_in_the_wild/compute_error_point_to_line_left_eye.m b/matlab_version/experiments_in_the_wild/compute_error_point_to_line_left_eye.m deleted file mode 100644 index 4b93b43..0000000 --- a/matlab_version/experiments_in_the_wild/compute_error_point_to_line_left_eye.m +++ /dev/null @@ -1,86 +0,0 @@ -function [ error_per_image ] = compute_error_point_to_line_left_eye( ground_truth_all, detected_points_all, occluded ) -%compute_error -% compute the average point-to-point Euclidean error normalized by the -% inter-ocular distance (measured as the Euclidean distance between the -% outer corners of the eyes) -% -% Inputs: -% grounth_truth_all, size: num_of_points x 2 x num_of_images -% detected_points_all, size: num_of_points x 2 x num_of_images -% Output: -% error_per_image, size: num_of_images x 1 - - - -right_eye_inds_from_68 = [37,38,39,40,41,42,37]; -right_eye_inds_from_28 = [9,11,13,15,17,19]; - -num_of_images = size(ground_truth_all,3); - -num_points_gt = size(ground_truth_all,1); - -num_points_det = size(detected_points_all,1); - -error_per_image = zeros(num_of_images,1); - -for i =1:num_of_images - - if(num_points_det == 6) - detected_points = detected_points_all(:,:,i); - elseif(num_points_det == 68 || num_points_det == 66) - detected_points = detected_points_all(right_eye_inds_from_68,:,i); - elseif(num_points_det == 28) - detected_points = detected_points_all(right_eye_inds_from_28,:,i); - elseif(num_points_det == 49) - - end - ground_truth_points = ground_truth_all(:,:,i); - - if(num_points_gt == 66 || num_points_gt == 68) - interocular_distance = norm(ground_truth_points(37,:)-ground_truth_points(46,:)); - ground_truth_points = ground_truth_points(right_eye_inds_from_68,:,:); - else - interocular_distance = norm(ground_truth_points(37-17,:)-ground_truth_points(46-17,:)); - ground_truth_points = ground_truth_points(right_eye_inds_from_68,:,:); - end - - sum=0; - for j=1:6 - - if(j== 1 || j == 6) - % eye corners should align perfectly - sum = sum + norm(detected_points(j,:)-ground_truth_points(j,:)); - else - % points between eye corners measured in distance to the two appropriate line - % segments - sum = sum + point_to_segments(detected_points(j,:), ground_truth_points(j-1:j+1,:)); - end - end - error_per_image(i) = sum/(6*interocular_distance); -end - -error_per_image = error_per_image(~occluded); - -end - -function seg_dist = point_to_segments(point, segments) - - seg_dists = zeros(size(segments, 1)-1,1); - - for i=1:size(segments, 1)-1 - - vec1 = point - segments(i,:); - vec2 = segments(i+1,:) - segments(i,:); - - d = (vec1 * vec2') / (norm(vec2)^2); - - if(d < 0) - seg_dists(i) = norm(vec1); - elseif(d > 1) - seg_dists(i) = norm(point - segments(i+1,:)); - else - seg_dists(i) = sqrt( norm(vec1)^2 - norm(d * vec2)^2); - end - end - seg_dist = min(seg_dists); -end \ No newline at end of file diff --git a/matlab_version/experiments_in_the_wild/compute_error_point_to_line_right_eye.m b/matlab_version/experiments_in_the_wild/compute_error_point_to_line_right_eye.m deleted file mode 100644 index b6dd94a..0000000 --- a/matlab_version/experiments_in_the_wild/compute_error_point_to_line_right_eye.m +++ /dev/null @@ -1,86 +0,0 @@ -function [ error_per_image ] = compute_error_point_to_line_right_eye( ground_truth_all, detected_points_all, occluded ) -%compute_error -% compute the average point-to-point Euclidean error normalized by the -% inter-ocular distance (measured as the Euclidean distance between the -% outer corners of the eyes) -% -% Inputs: -% grounth_truth_all, size: num_of_points x 2 x num_of_images -% detected_points_all, size: num_of_points x 2 x num_of_images -% Output: -% error_per_image, size: num_of_images x 1 - - - -right_eye_inds_from_68 = [43,44,45,46,47,48,43]; -right_eye_inds_from_28 = [9,11,13,15,17,19]; - -num_of_images = size(ground_truth_all,3); - -num_points_gt = size(ground_truth_all,1); - -num_points_det = size(detected_points_all,1); - -error_per_image = zeros(num_of_images,1); - -for i =1:num_of_images - - if(num_points_det == 6) - detected_points = detected_points_all(:,:,i); - elseif(num_points_det == 68 || num_points_det == 66) - detected_points = detected_points_all(right_eye_inds_from_68,:,i); - elseif(num_points_det == 28) - detected_points = detected_points_all(right_eye_inds_from_28,:,i); - elseif(num_points_det == 49) - - end - ground_truth_points = ground_truth_all(:,:,i); - - if(num_points_gt == 66 || num_points_gt == 68) - interocular_distance = norm(ground_truth_points(37,:)-ground_truth_points(46,:)); - ground_truth_points = ground_truth_points(right_eye_inds_from_68,:,:); - else - interocular_distance = norm(ground_truth_points(37-17,:)-ground_truth_points(46-17,:)); - ground_truth_points = ground_truth_points(right_eye_inds_from_68,:,:); - end - - sum=0; - for j=1:6 - - if(j== 1 || j == 6) - % eye corners should align perfectly - sum = sum + norm(detected_points(j,:)-ground_truth_points(j,:)); - else - % points between eye corners measured in distance to the two appropriate line - % segments - sum = sum + point_to_segments(detected_points(j,:), ground_truth_points(j-1:j+1,:)); - end - end - error_per_image(i) = sum/(6*interocular_distance); -end - -error_per_image = error_per_image(~occluded); - -end - -function seg_dist = point_to_segments(point, segments) - - seg_dists = zeros(size(segments, 1)-1,1); - - for i=1:size(segments, 1)-1 - - vec1 = point - segments(i,:); - vec2 = segments(i+1,:) - segments(i,:); - - d = (vec1 * vec2') / (norm(vec2)^2); - - if(d < 0) - seg_dists(i) = norm(vec1); - elseif(d > 1) - seg_dists(i) = norm(point - segments(i+1,:)); - else - seg_dists(i) = sqrt( norm(vec1)^2 - norm(d * vec2)^2); - end - end - seg_dist = min(seg_dists); -end \ No newline at end of file diff --git a/matlab_version/experiments_in_the_wild/Script_CLNF_general_eyes.m b/matlab_version/experiments_in_the_wild/hierarch_checks/Script_CLNF_general_eyes.m similarity index 100% rename from matlab_version/experiments_in_the_wild/Script_CLNF_general_eyes.m rename to matlab_version/experiments_in_the_wild/hierarch_checks/Script_CLNF_general_eyes.m diff --git a/matlab_version/experiments_in_the_wild/hierarch_checks/Script_PDM_eyes.m b/matlab_version/experiments_in_the_wild/hierarch_checks/Script_PDM_eyes.m index 955524d..e83a29d 100644 --- a/matlab_version/experiments_in_the_wild/hierarch_checks/Script_PDM_eyes.m +++ b/matlab_version/experiments_in_the_wild/hierarch_checks/Script_PDM_eyes.m @@ -27,8 +27,12 @@ pdm.M = double(M); pdm.E = double(E); pdm.V = double(V); +num_points = numel(M)/3; + +errors = zeros(numel(images),1); shapes_all = zeros(size(labels,2),size(labels,3), size(labels,1)); labels_all = zeros(size(labels,2),size(labels,3), size(labels,1)); +errors_normed = zeros(numel(images),1); errors_left_eye = zeros(numel(images),1); errors_right_eye = zeros(numel(images),1); @@ -36,30 +40,41 @@ errors_right_eye = zeros(numel(images),1); tic for i=1:numel(images) + image = imread(images(i).img); + image_orig = image; + + if(size(image,3) == 3) + image = rgb2gray(image); + end + labels_curr = squeeze(labels(i,:,:)); - [ a, R, T, ~, l_params, err, shapeOrtho] = fit_PDM_ortho_proj_to_2D_no_reg(pdm.M, pdm.E, pdm.V, labels_curr); + [ a, R, T, ~, l_params, err, shapeOrtho] = fit_PDM_ortho_proj_to_2D(pdm.M, pdm.E, pdm.V, labels_curr); + shape = shapeOrtho; shapes_all(:,:,i) = shapeOrtho; labels_all(:,:,i) = labels_curr; - if(mod(i, 100)==0) + if(mod(i, 200)==0) fprintf('%d done\n', i ); end + valid_points = sum(squeeze(labels(i,:,:)),2) > 0; + valid_points(1:17) = 0; + actualShape = squeeze(labels(i,:,:)); + errors(i) = sqrt(mean(sum((actualShape(valid_points,:) - shape(valid_points,:)).^2,2))); + width = ((max(actualShape(valid_points,1)) - min(actualShape(valid_points,1)))+(max(actualShape(valid_points,2)) - min(actualShape(valid_points,2))))/2; + errors_normed(i) = errors(i)/width; errors_left_eye(i) = compute_error_point_to_line_left_eye(actualShape, shapeOrtho, [0]); errors_right_eye(i) = compute_error_point_to_line_right_eye(actualShape, shapeOrtho, [0]); - if(errors_left_eye(i) > 0.02 || errors_right_eye(i) > 0.02) - plot(shapeOrtho(:,1), -shapeOrtho(:,2), 'r.'); hold on; - axis equal; - plot(labels_curr(:,1), -labels_curr(:,2), 'g.'); hold off; + if(errors_normed(i) > 0.035 || errors_left_eye(i) > 0.035 || errors_right_eye(i) > 0.035) + imshow(image);hold on; plot(shape(:,1), shape(:,2), '.g'); hold off; end - end -save('Errors_PDM_eyes.mat', 'errors_left_eye', 'errors_right_eye'); +save('Errors_PDM_eyes.mat', 'errors_normed', 'errors_left_eye', 'errors_right_eye'); end diff --git a/matlab_version/experiments_in_the_wild/hierarch_checks/Script_PDM_general.m b/matlab_version/experiments_in_the_wild/hierarch_checks/Script_PDM_general.m index 119ffd2..fb52e2e 100644 --- a/matlab_version/experiments_in_the_wild/hierarch_checks/Script_PDM_general.m +++ b/matlab_version/experiments_in_the_wild/hierarch_checks/Script_PDM_general.m @@ -1,4 +1,4 @@ -function Script_PDM_eyes() +function Script_PDM_general() addpath('../PDM_helpers/'); addpath('../fitting/normxcorr2_mex_ALL'); @@ -27,8 +27,12 @@ pdm.M = double(M); pdm.E = double(E); pdm.V = double(V); +num_points = numel(M)/3; + +errors = zeros(numel(images),1); shapes_all = zeros(size(labels,2),size(labels,3), size(labels,1)); labels_all = zeros(size(labels,2),size(labels,3), size(labels,1)); +errors_normed = zeros(numel(images),1); errors_left_eye = zeros(numel(images),1); errors_right_eye = zeros(numel(images),1); @@ -36,31 +40,41 @@ errors_right_eye = zeros(numel(images),1); tic for i=1:numel(images) + image = imread(images(i).img); + image_orig = image; + + if(size(image,3) == 3) + image = rgb2gray(image); + end + labels_curr = squeeze(labels(i,:,:)); - [ a, R, T, ~, l_params, err, shapeOrtho] = fit_PDM_ortho_proj_to_2D_no_reg(pdm.M, pdm.E, pdm.V, labels_curr); + [ a, R, T, ~, l_params, err, shapeOrtho] = fit_PDM_ortho_proj_to_2D(pdm.M, pdm.E, pdm.V, labels_curr); + shape = shapeOrtho; shapes_all(:,:,i) = shapeOrtho; labels_all(:,:,i) = labels_curr; - if(mod(i, 100)==0) + if(mod(i, 200)==0) fprintf('%d done\n', i ); end + valid_points = sum(squeeze(labels(i,:,:)),2) > 0; + valid_points(1:17) = 0; + actualShape = squeeze(labels(i,:,:)); + errors(i) = sqrt(mean(sum((actualShape(valid_points,:) - shape(valid_points,:)).^2,2))); + width = ((max(actualShape(valid_points,1)) - min(actualShape(valid_points,1)))+(max(actualShape(valid_points,2)) - min(actualShape(valid_points,2))))/2; + errors_normed(i) = errors(i)/width; errors_left_eye(i) = compute_error_point_to_line_left_eye(actualShape, shapeOrtho, [0]); errors_right_eye(i) = compute_error_point_to_line_right_eye(actualShape, shapeOrtho, [0]); - - if(errors_left_eye(i) > 0.02 || errors_right_eye(i) > 0.02) - plot(shapeOrtho(:,1), -shapeOrtho(:,2), 'r.'); hold on; - axis equal; - plot(labels_curr(:,1), -labels_curr(:,2), 'g.'); hold off; + if(errors_normed(i) > 0.035 || errors_left_eye(i) > 0.035 || errors_right_eye(i) > 0.035) + imshow(image);hold on; plot(shape(:,1), shape(:,2), '.g'); hold off; end - end -save('Errors_PDM_basic.mat', 'errors_left_eye', 'errors_right_eye'); +save('Errors_PDM_basic.mat', 'errors_normed', 'errors_left_eye', 'errors_right_eye'); end diff --git a/matlab_version/experiments_in_the_wild/compute_brow_error_to_line.m b/matlab_version/experiments_in_the_wild/hierarch_checks/compute_brow_error_to_line.m similarity index 100% rename from matlab_version/experiments_in_the_wild/compute_brow_error_to_line.m rename to matlab_version/experiments_in_the_wild/hierarch_checks/compute_brow_error_to_line.m diff --git a/matlab_version/experiments_in_the_wild/hierarch_checks/compute_error_point_to_line_left_eye.m b/matlab_version/experiments_in_the_wild/hierarch_checks/compute_error_point_to_line_left_eye.m index c2edd30..4b93b43 100644 --- a/matlab_version/experiments_in_the_wild/hierarch_checks/compute_error_point_to_line_left_eye.m +++ b/matlab_version/experiments_in_the_wild/hierarch_checks/compute_error_point_to_line_left_eye.m @@ -59,9 +59,7 @@ for i =1:num_of_images error_per_image(i) = sum/(6*interocular_distance); end -if(nargin > 2) - error_per_image = error_per_image(~occluded); -end +error_per_image = error_per_image(~occluded); end diff --git a/matlab_version/experiments_in_the_wild/hierarch_checks/compute_error_point_to_line_right_eye.m b/matlab_version/experiments_in_the_wild/hierarch_checks/compute_error_point_to_line_right_eye.m index e03fb47..b6dd94a 100644 --- a/matlab_version/experiments_in_the_wild/hierarch_checks/compute_error_point_to_line_right_eye.m +++ b/matlab_version/experiments_in_the_wild/hierarch_checks/compute_error_point_to_line_right_eye.m @@ -59,9 +59,7 @@ for i =1:num_of_images error_per_image(i) = sum/(6*interocular_distance); end -if(nargin > 2) - error_per_image = error_per_image(~occluded); -end +error_per_image = error_per_image(~occluded); end diff --git a/matlab_version/models/Load_CLM_params_eye_28.m b/matlab_version/models/Load_CLM_params_eye_28.m new file mode 100644 index 0000000..a5b8ea5 --- /dev/null +++ b/matlab_version/models/Load_CLM_params_eye_28.m @@ -0,0 +1,38 @@ +function [ clmParams, pdm_right, pdm_left ] = Load_CLM_params_eye_28() +%LOAD_CLM_PARAMS_WILD Summary of this function goes here +% Detailed explanation goes here + clmParams.window_size = [17,17; 15,15; 13,13;]; + clmParams.numPatchIters = size(clmParams.window_size,1); + + % the PDM created from in the wild data + pdmLoc = ['../models/hierarch_pdm/pdm_28_r_eye.mat']; + + load(pdmLoc); + + pdm_right = struct; + pdm_right.M = double(M); + pdm_right.E = double(E); + pdm_right.V = double(V); + + pdmLoc = ['../models/hierarch_pdm/pdm_28_l_eye.mat']; + + load(pdmLoc); + + pdm_left = struct; + pdm_left.M = double(M); + pdm_left.E = double(E); + pdm_left.V = double(V); + + % the default model parameters to use + clmParams.regFactor = 2.0; + clmParams.sigmaMeanShift = 1.5; + clmParams.tikhonov_factor = 0; + + clmParams.startScale = 1; + clmParams.num_RLMS_iter = 10; + clmParams.fTol = 0.01; + clmParams.useMultiScale = true; + clmParams.use_multi_modal = 0; + clmParams.tikhonov_factor = 0; +end + diff --git a/matlab_version/models/hierarch/ccnf_patches_0.75_synth_left_eye.mat b/matlab_version/models/hierarch/ccnf_patches_0.75_synth_left_eye.mat new file mode 100644 index 0000000..919a6a3 Binary files /dev/null and b/matlab_version/models/hierarch/ccnf_patches_0.75_synth_left_eye.mat differ diff --git a/matlab_version/models/hierarch/ccnf_patches_0.75_synth_right_eye.mat b/matlab_version/models/hierarch/ccnf_patches_0.75_synth_right_eye.mat new file mode 100644 index 0000000..60244e2 Binary files /dev/null and b/matlab_version/models/hierarch/ccnf_patches_0.75_synth_right_eye.mat differ diff --git a/matlab_version/models/hierarch/ccnf_patches_1.00_synth_left_eye.mat b/matlab_version/models/hierarch/ccnf_patches_1.00_synth_left_eye.mat new file mode 100644 index 0000000..9969757 Binary files /dev/null and b/matlab_version/models/hierarch/ccnf_patches_1.00_synth_left_eye.mat differ diff --git a/matlab_version/models/hierarch/ccnf_patches_1.00_synth_right_eye.mat b/matlab_version/models/hierarch/ccnf_patches_1.00_synth_right_eye.mat new file mode 100644 index 0000000..57c42df Binary files /dev/null and b/matlab_version/models/hierarch/ccnf_patches_1.00_synth_right_eye.mat differ diff --git a/matlab_version/models/hierarch/ccnf_patches_1.50_synth_left_eye.mat b/matlab_version/models/hierarch/ccnf_patches_1.50_synth_left_eye.mat new file mode 100644 index 0000000..21170af Binary files /dev/null and b/matlab_version/models/hierarch/ccnf_patches_1.50_synth_left_eye.mat differ diff --git a/matlab_version/models/hierarch/ccnf_patches_1.50_synth_right_eye.mat b/matlab_version/models/hierarch/ccnf_patches_1.50_synth_right_eye.mat new file mode 100644 index 0000000..deec91b Binary files /dev/null and b/matlab_version/models/hierarch/ccnf_patches_1.50_synth_right_eye.mat differ diff --git a/matlab_version/models/hierarch_pdm/pdm_28_l_eye.mat b/matlab_version/models/hierarch_pdm/pdm_28_l_eye.mat new file mode 100644 index 0000000..3c224d6 Binary files /dev/null and b/matlab_version/models/hierarch_pdm/pdm_28_l_eye.mat differ diff --git a/matlab_version/models/hierarch_pdm/pdm_28_r_eye.mat b/matlab_version/models/hierarch_pdm/pdm_28_r_eye.mat new file mode 100644 index 0000000..ea364f0 Binary files /dev/null and b/matlab_version/models/hierarch_pdm/pdm_28_r_eye.mat differ