eos  0.7.1
Classes | Functions
eos::morphablemodel Namespace Reference

Functionality to represent a Morphable Model, containing it's PCA models and loading functions. More...

Classes

struct  Blendshape
 A class representing a 3D blendshape. More...
 
class  MorphableModel
 A class representing a 3D Morphable Model, consisting of a shape- and colour (albedo) PCA model. More...
 
class  PcaModel
 This class represents a PCA-model that consists of: More...
 

Functions

std::vector< Blendshapeload_blendshapes (std::string filename)
 
void save_coefficients (std::vector< float > coefficients, std::string filename)
 
std::vector< cv::Vec2f > load_isomap (boost::filesystem::path isomap_file)
 
MorphableModel load_scm_model (boost::filesystem::path model_filename, boost::filesystem::path isomap_file=boost::filesystem::path())
 
MorphableModel load_model (std::string filename)
 
void save_model (MorphableModel model, std::string filename)
 
cv::Mat normalise_pca_basis (cv::Mat unnormalised_basis, cv::Mat eigenvalues)
 
cv::Mat unnormalise_pca_basis (cv::Mat normalised_basis, cv::Mat eigenvalues)
 

Detailed Description

Functionality to represent a Morphable Model, containing it's PCA models and loading functions.

Function Documentation

std::vector<Blendshape> eos::morphablemodel::load_blendshapes ( std::string  filename)

Helper method to load a file with blendshapes from a cereal::BinaryInputArchive from the harddisk.

Parameters
[in]filenameFilename to a blendshapes-file.
Returns
The loaded blendshapes.
Exceptions
std::runtime_errorWhen the file given in filename fails to be opened (most likely because the file doesn't exist).
std::vector< cv::Vec2f > eos::morphablemodel::load_isomap ( boost::filesystem::path  isomapFile)

Load a set of 2D texture coordinates pre-generated by the isomap algorithm. After loading, we rescale the coordinates to [0, 1] x [0, 1].

Parameters
[in]isomapFilePath to an isomap file containing texture coordinates.
Returns
The 2D texture coordinates for every vertex.
Exceptions
...
MorphableModel eos::morphablemodel::load_model ( std::string  filename)

Helper method to load a Morphable Model from a cereal::BinaryInputArchive from the harddisk.

Parameters
[in]filenameFilename to a model.
Returns
The loaded Morphable Model.
Exceptions
std::runtime_errorWhen the file given in filename fails to be opened (most likely because the file doesn't exist).
MorphableModel eos::morphablemodel::load_scm_model ( boost::filesystem::path  model_filename,
boost::filesystem::path  isomap_file = boost::filesystem::path() 
)

Load a shape or color model from a .scm file containing a Morphable Model in the Surrey format. CVSSP's software internally trains and stores the model in this custom binary format and this class provides means to load them.

Note on multi-resolution models: The landmarks to vertex-id mapping is always the same. The lowest resolution model has all the landmarks defined and for the higher resolutions, the mesh is divided from that on. Note: For new landmarks we add, this might not be the case if we add them in the highest resolution model, so take care!

  • The pcaBasis matrix stored in the file and loaded is the orthogonal PCA basis, i.e. it is not normalised by the eigenvalues.
Parameters
[in]model_filenameA binary .scm-file containing the model.
[in]isomap_fileAn optional path to an isomap containing texture coordinates.
Returns
The Morphable Model loaded from the file.
Exceptions
...
cv::Mat eos::morphablemodel::normalise_pca_basis ( cv::Mat  unnormalised_basis,
cv::Mat  eigenvalues 
)
inline

Takes an unnormalised PCA basis matrix (a matrix consisting of the eigenvectors and normalises it, i.e. multiplies each eigenvector by the square root of its corresponding eigenvalue.

Parameters
[in]unnormalised_basisAn unnormalised PCA basis matrix.
[in]eigenvaluesA row or column vector of eigenvalues.
Returns
The normalised PCA basis matrix.
void eos::morphablemodel::save_coefficients ( std::vector< float >  coefficients,
std::string  filename 
)

Saves coefficients (for example PCA shape coefficients) to a json file.

Parameters
[in]coefficientsA vector of coefficients.
[in]filenameThe file to write.
Exceptions
std::runtime_errorif unable to open the given file for writing.
void eos::morphablemodel::save_model ( MorphableModel  model,
std::string  filename 
)

Helper method to save a Morphable Model to the harddrive as cereal::BinaryInputArchive.

Parameters
[in]modelThe model to be saved.
[in]filenameFilename for the model.
cv::Mat eos::morphablemodel::unnormalise_pca_basis ( cv::Mat  normalised_basis,
cv::Mat  eigenvalues 
)
inline

Takes a normalised PCA basis matrix (a matrix consisting of the eigenvectors and denormalises it, i.e. multiplies each eigenvector by 1 over the square root of its corresponding eigenvalue.

Parameters
[in]normalised_basisA normalised PCA basis matrix.
[in]eigenvaluesA row or column vector of eigenvalues.
Returns
The unnormalised PCA basis matrix.