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, ... ...@@ -26,15 +26,11 @@ function [mesh, rendering_parameters] = fit_shape_and_pose(morphable_model, ...
% contour_landmarks and model_contour as *filenames* to the respective % contour_landmarks and model_contour as *filenames* to the respective
% files in the eos/share/ directory, and not the objects directly. % files in the eos/share/ directory, and not the objects directly.
morphable_model = '../share/sfm_shape_3448.bin'; % We'll use default values to the following arguments, if they're not
blendshapes = '../share/expression_blendshapes_3448.bin'; % provided:
landmarks = zeros(68, 2); if (~exist('edge_topology', 'var')), edge_topology = '../share/sfm_3448_edge_topology.json'; end
landmark_mapper = '../share/ibug2did.txt'; if (~exist('contour_landmarks', 'var')), contour_landmarks = '../share/ibug2did.txt'; end
image_width = 1280; if (~exist('model_contour', 'var')), model_contour = '../share/model_contours.json'; end
image_height = 720;
edge_topology = '../share/sfm_3448_edge_topology.json';
contour_landmarks = '../share/ibug2did.txt';
model_contour = '../share/model_contours.json';
if (~exist('num_iterations', 'var')), num_iterations = 5; 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('num_shape_coefficients_to_fit', 'var')), num_shape_coefficients_to_fit = -1; end
if (~exist('lambda', 'var')), lambda = 30.0; end if (~exist('lambda', 'var')), lambda = 30.0; end
......
...@@ -3,42 +3,38 @@ ...@@ -3,42 +3,38 @@
%% Set up some required paths to files: %% Set up some required paths to files:
model_file = '../share/sfm_shape_3448.bin'; model_file = '../share/sfm_shape_3448.bin';
blendshapes_file = '../share/expression_blendshapes_3448.bin'; blendshapes_file = '../share/expression_blendshapes_3448.bin';
landmark_mappings = '../share/ibug2did.txt';
%% Read some ibug landmarks for an image: %% Load an image and its landmarks in ibug format:
landmarks = read_pts_landmarks('D:\Github\data\ibug\helen\testset\30427236_1.pts'); 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: %% 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); figure(1);
plot3(mesh.vertices(:,1), mesh.vertices(:,2), mesh.vertices(:,3), '.'); plot3(mesh.vertices(:, 1), mesh.vertices(:, 2), mesh.vertices(:, 3), '.');
% or... % or...
FV.vertices = mesh.vertices(:,1:3); FV.vertices = mesh.vertices(:, 1:3);
FV.faces = mesh.tvi; FV.faces = mesh.tvi;
figure(2); figure(2);
patch(FV, 'FaceColor', [1 1 1], 'EdgeColor', 'none', 'FaceLighting', 'phong'); light; axis equal; axis off; 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: %% Visualise the fitting in 2D, on top of the input image:
% First we project all vertices to 2D: % Project all vertices to 2D:
points_2d = zeros(size(mesh.vertices, 1), 2); points_2d = mesh.vertices * (render_params.viewport*render_params.projection*render_params.modelview)';
h = 720; w = 1280; % Display the image and plot the projected mesh points on top of it:
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');
figure(3); figure(3);
imshow(img); imshow(image);
hold on; 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: % 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: %% Just a helper function to read ibug .pts landmarks from a file:
......
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