Commit 6033ef4f authored by Patrik Huber's avatar Patrik Huber

Added code to represent and load blendshapes

parent 07b4b0e0
......@@ -92,6 +92,7 @@ set(HEADERS
include/eos/core/LandmarkMapper.hpp
include/eos/morphablemodel/PcaModel.hpp
include/eos/morphablemodel/MorphableModel.hpp
include/eos/morphablemodel/Blendshape.hpp
include/eos/morphablemodel/io/cvssp.hpp
include/eos/morphablemodel/io/mat_cerealisation.hpp
include/eos/fitting/affine_camera_estimation.hpp
......
/*
* Eos - A 3D Morphable Model fitting library written in modern C++11/14.
*
* File: include/eos/morphablemodel/Blendshape.hpp
*
* Copyright 2015 Patrik Huber
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#pragma once
#ifndef BLENDSHAPE_HPP_
#define BLENDSHAPE_HPP_
#include "eos/morphablemodel/io/mat_cerealisation.hpp"
#include "cereal/types/string.hpp"
#include "cereal/archives/binary.hpp"
#include "opencv2/core/core.hpp"
#include <string>
#include <fstream>
namespace eos {
namespace morphablemodel {
/**
* @brief A class representing a 3D blendshape.
*
* A blendshape is a vector of offsets that transform the vertices of
* a given mesh or shape instance. Usually, a blendshape is associated
* with a deformation like a particular facial expression or a phoneme.
*/
struct Blendshape
{
std::string name; ///< Name of the blendshape.
cv::Mat deformation; ///< A 3m x 1 col-vector (xyzxyz...)', where m is the number of model-vertices. Has the same format as PcaModel::mean.
friend class cereal::access;
/**
* Serialises this class using cereal.
*
* @param[in] ar The archive to serialise to (or to serialise from).
*/
template<class Archive>
void serialize(Archive& archive)
{
archive(name, deformation);
};
};
/**
* Helper method to load a file with blendshapes from
* a cereal::BinaryInputArchive from the harddisk.
*
* @param[in] filename Filename to a blendshapes-file.
* @return The loaded blendshapes.
* @throw std::runtime_error When the file given in \c filename fails to be opened (most likely because the file doesn't exist).
*/
std::vector<Blendshape> load_blendshapes(std::string filename)
{
std::vector<Blendshape> blendshapes;
std::ifstream file(filename, std::ios::binary);
if (file.fail()) {
throw std::runtime_error("Error opening given file: " + filename);
}
cereal::BinaryInputArchive input_archive(file);
input_archive(blendshapes);
return blendshapes;
};
} /* namespace morphablemodel */
} /* namespace eos */
#endif /* BLENDSHAPE_HPP_ */
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