Commit dbf6d153 authored by Patrik Huber's avatar Patrik Huber

Updated Matlab demo code

parent 7aa30194
......@@ -26,15 +26,11 @@ function [mesh, rendering_parameters] = fit_shape_and_pose(morphable_model, ...
% contour_landmarks and model_contour as *filenames* to the respective
% files in the eos/share/ directory, and not the objects directly.
morphable_model = '../share/sfm_shape_3448.bin';
blendshapes = '../share/expression_blendshapes_3448.bin';
landmarks = zeros(68, 2);
landmark_mapper = '../share/ibug2did.txt';
image_width = 1280;
image_height = 720;
edge_topology = '../share/sfm_3448_edge_topology.json';
contour_landmarks = '../share/ibug2did.txt';
model_contour = '../share/model_contours.json';
% We'll use default values to the following arguments, if they're not
% provided:
if (~exist('edge_topology', 'var')), edge_topology = '../share/sfm_3448_edge_topology.json'; end
if (~exist('contour_landmarks', 'var')), contour_landmarks = '../share/ibug2did.txt'; end
if (~exist('model_contour', 'var')), model_contour = '../share/model_contours.json'; end
if (~exist('num_iterations', 'var')), num_iterations = 5; end
if (~exist('num_shape_coefficients_to_fit', 'var')), num_shape_coefficients_to_fit = -1; end
if (~exist('lambda', 'var')), lambda = 30.0; end
......
......@@ -3,42 +3,38 @@
%% Set up some required paths to files:
model_file = '../share/sfm_shape_3448.bin';
blendshapes_file = '../share/expression_blendshapes_3448.bin';
landmark_mappings = '../share/ibug2did.txt';
%% Read some ibug landmarks for an image:
landmarks = read_pts_landmarks('D:\Github\data\ibug\helen\testset\30427236_1.pts');
%% Load an image and its landmarks in ibug format:
image = imread('../bin/data/image_0010.png');
landmarks = read_pts_landmarks('../bin/data/image_0010.pts');
image_width = size(image, 2); image_height = size(image, 1);
%% Run the fitting, get back the fitted mesh and pose:
[mesh, render_params] = eos.fitting.fit_shape_and_pose(model_file, blendshapes_file, landmarks);
[mesh, render_params] = eos.fitting.fit_shape_and_pose(model_file, blendshapes_file, landmarks, landmark_mappings, image_width, image_height);
% Note: The function actually has a few more arguments to files it
% needs. If you're not running it from within eos/matlab/, you need to
% provide them. See its documentation and .m file.
%% Visualise the fitted mesh using your favourite tool, for example...
%% Visualise the fitted mesh using your favourite plot, for example...
figure(1);
plot3(mesh.vertices(:,1), mesh.vertices(:,2), mesh.vertices(:,3), '.');
plot3(mesh.vertices(:, 1), mesh.vertices(:, 2), mesh.vertices(:, 3), '.');
% or...
FV.vertices = mesh.vertices(:,1:3);
FV.vertices = mesh.vertices(:, 1:3);
FV.faces = mesh.tvi;
figure(2);
patch(FV, 'FaceColor', [1 1 1], 'EdgeColor', 'none', 'FaceLighting', 'phong'); light; axis equal; axis off;
%% Visualise the fitting in 2D, on top of the input image:
% First we project all vertices to 2D:
points_2d = zeros(size(mesh.vertices, 1), 2);
h = 720; w = 1280;
viewport = [0, h, w, -h];
for i=1:size(mesh.vertices, 1)
tmp = render_params.projection*render_params.modelview*mesh.vertices(i, :)';
tmp = tmp .* 0.5 + 0.5;
tmp(1) = tmp(1) * viewport(3) + viewport(1);
tmp(2) = tmp(2) * viewport(4) + viewport(2);
points_2d(i, :) = tmp(1:2);
end
% Load the image, plot the projected mesh points on top of it:
img = imread('D:\Github\data\ibug\helen\testset\30427236_1.jpg');
% Project all vertices to 2D:
points_2d = mesh.vertices * (render_params.viewport*render_params.projection*render_params.modelview)';
% Display the image and plot the projected mesh points on top of it:
figure(3);
imshow(img);
imshow(image);
hold on;
plot(points_2d(:,1), points_2d(:,2), 'g.');
plot(points_2d(:, 1), points_2d(:, 2), 'g.');
% We can also plot the landmarks the mesh was fitted to:
plot(landmarks(:,1), landmarks(:,2), 'ro');
plot(landmarks(:, 1), landmarks(:, 2), 'ro');
%% Just a helper function to read ibug .pts landmarks from a file:
......@@ -56,4 +52,4 @@ for i=6:2:141
row_idx = row_idx + 1;
end
end
\ No newline at end of file
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment