25 #include "eos/morphablemodel/MorphableModel.hpp" 26 #include "eos/morphablemodel/Blendshape.hpp" 27 #include "eos/fitting/linear_shape_fitting.hpp" 28 #include "eos/fitting/blendshape_fitting.hpp" 30 #include "opencv2/core/core.hpp" 58 cv::Mat
fit_shape(cv::Mat affine_camera_matrix,
eos::morphablemodel::MorphableModel morphable_model, std::vector<eos::morphablemodel::Blendshape> blendshapes, std::vector<cv::Vec2f> image_points, std::vector<int> vertex_indices,
float lambda, boost::optional<int> num_coefficients_to_fit, std::vector<float>& pca_shape_coefficients, std::vector<float>& blendshape_coefficients)
62 Mat blendshapes_as_basis(blendshapes[0].deformation.rows, blendshapes.size(), CV_32FC1);
63 for (
int i = 0; i < blendshapes.size(); ++i)
65 blendshapes[i].deformation.copyTo(blendshapes_as_basis.col(i));
68 std::vector<float> last_blendshape_coeffs, current_blendshape_coeffs;
69 std::vector<float> last_pca_coeffs, current_pca_coeffs;
70 current_blendshape_coeffs.resize(blendshapes.size());
76 last_blendshape_coeffs = current_blendshape_coeffs;
77 last_pca_coeffs = current_pca_coeffs;
79 Mat mean_plus_blendshapes = morphable_model.
get_shape_model().
get_mean() + blendshapes_as_basis * Mat(last_blendshape_coeffs);
86 combined_shape = pca_model_shape + blendshapes_as_basis * Mat(current_blendshape_coeffs);
87 }
while (std::abs(cv::norm(current_pca_coeffs) - cv::norm(last_pca_coeffs)) >= 0.01 || std::abs(cv::norm(current_blendshape_coeffs) - cv::norm(last_blendshape_coeffs)) >= 0.01);
89 pca_shape_coefficients = current_pca_coeffs;
90 blendshape_coefficients = current_blendshape_coeffs;
91 return combined_shape;
108 cv::Mat
fit_shape(cv::Mat affine_camera_matrix,
eos::morphablemodel::MorphableModel morphable_model, std::vector<eos::morphablemodel::Blendshape> blendshapes, std::vector<cv::Vec2f> image_points, std::vector<int> vertex_indices,
float lambda = 3.0f, boost::optional<int> num_coefficients_to_fit = boost::optional<int>())
110 std::vector<float> unused;
111 return fit_shape(affine_camera_matrix, morphable_model, blendshapes, image_points, vertex_indices, lambda, num_coefficients_to_fit, unused, unused);
cv::Mat draw_sample(float sigma=1.0f)
Definition: PcaModel.hpp:143
Namespace containing all of eos's 3D model fitting functionality.
std::vector< float > fit_shape_to_landmarks_linear(morphablemodel::MorphableModel morphable_model, cv::Mat affine_camera_matrix, std::vector< cv::Vec2f > landmarks, std::vector< int > vertex_ids, cv::Mat base_face=cv::Mat(), float lambda=3.0f, boost::optional< int > num_coefficients_to_fit=boost::optional< int >(), boost::optional< float > detector_standard_deviation=boost::optional< float >(), boost::optional< float > model_standard_deviation=boost::optional< float >())
Definition: linear_shape_fitting.hpp:60
cv::Mat get_mean() const
Definition: PcaModel.hpp:119
PcaModel get_shape_model() const
Definition: MorphableModel.hpp:77
std::vector< float > fit_blendshapes_to_landmarks_linear(std::vector< eos::morphablemodel::Blendshape > blendshapes, cv::Mat face_instance, cv::Mat affine_camera_matrix, std::vector< cv::Vec2f > landmarks, std::vector< int > vertex_ids, float lambda=500.0f)
Definition: blendshape_fitting.hpp:50
cv::Mat fit_shape(cv::Mat affine_camera_matrix, eos::morphablemodel::MorphableModel morphable_model, std::vector< eos::morphablemodel::Blendshape > blendshapes, std::vector< cv::Vec2f > image_points, std::vector< int > vertex_indices, float lambda, boost::optional< int > num_coefficients_to_fit, std::vector< float > &pca_shape_coefficients, std::vector< float > &blendshape_coefficients)
Definition: fitting.hpp:58
A class representing a 3D Morphable Model, consisting of a shape- and colour (albedo) PCA model...
Definition: MorphableModel.hpp:54