Commit b7b87126 authored by Patrik Huber's avatar Patrik Huber

Added working bindings for loading and using a MorphableModel

Put things from the morphablemodel namespace in a python submodule.
parent e0027ba7
...@@ -18,20 +18,26 @@ ...@@ -18,20 +18,26 @@
* limitations under the License. * limitations under the License.
*/ */
#include "eos/morphablemodel/PcaModel.hpp" #include "eos/morphablemodel/PcaModel.hpp"
#include "eos/morphablemodel/MorphableModel.hpp"
#include "opencv2/core/core.hpp" #include "opencv2/core/core.hpp"
#include "pybind11/pybind11.h" #include "pybind11/pybind11.h"
#include "pybind11/stl.h"
namespace py = pybind11; namespace py = pybind11;
using namespace eos;
/** /**
* Generate python bindings for the eos library using pybind11. * Generate python bindings for the eos library using pybind11.
*/ */
PYBIND11_PLUGIN(eos) { PYBIND11_PLUGIN(eos) {
py::module m("eos", "Python bindings to the 3D Morphable Face Model fitting library"); py::module eos_module("eos", "Python bindings to the 3D Morphable Face Model fitting library");
py::class_<cv::Vec4f>(m, "Vec4f", "Wrapper for OpenCV's cv::Vec4f type") /**
* General bindings, for OpenCV vector types and stuff:
*/
py::class_<cv::Vec4f>(eos_module, "Vec4f", "Wrapper for OpenCV's cv::Vec4f type")
.def_buffer([](cv::Vec4f &vec) -> py::buffer_info { .def_buffer([](cv::Vec4f &vec) -> py::buffer_info {
return py::buffer_info( return py::buffer_info(
&vec.val, /* Pointer to buffer */ &vec.val, /* Pointer to buffer */
...@@ -44,10 +50,24 @@ PYBIND11_PLUGIN(eos) { ...@@ -44,10 +50,24 @@ PYBIND11_PLUGIN(eos) {
); );
}); });
py::class_<eos::morphablemodel::PcaModel>(m, "PcaModel", "Class representing a PcaModel with a mean, eigenvectors and eigenvalues.") /**
.def(py::init<>()) * Bindings for the eos::morphablemodel namespace:
.def("get_mean_at_point", &eos::morphablemodel::PcaModel::get_mean_at_point, "Returns the mean at the given vertex id.") */
py::module morphablemodel_module = eos_module.def_submodule("morphablemodel", "Doc for submodule.");
py::class_<morphablemodel::PcaModel>(morphablemodel_module, "PcaModel", "Class representing a PcaModel with a mean, eigenvectors and eigenvalues, as well as a list of triangles to build a mesh.")
.def("get_num_principal_components", &morphablemodel::PcaModel::get_num_principal_components, "Returns the number of principal components in the model.")
.def("get_data_dimension", &morphablemodel::PcaModel::get_data_dimension, "Returns the dimension of the data, i.e. the number of shape dimensions.")
.def("get_triangle_list", &morphablemodel::PcaModel::get_triangle_list, "Returns a list of triangles on how to assemble the vertices into a mesh.")
.def("get_mean_at_point", &morphablemodel::PcaModel::get_mean_at_point, "Return the value of the mean at a given vertex index.")
;
py::class_<morphablemodel::MorphableModel>(morphablemodel_module, "MorphableModel", "A class representing a 3D Morphable Model, consisting of a shape- and colour (albedo) PCA model, as well as texture (uv) coordinates.")
.def("get_shape_model", [](const morphablemodel::MorphableModel& m) { return m.get_shape_model(); }, "Returns the PCA shape model of this Morphable Model.") // Not sure if that'll really be const in Python? I think Python does a copy each time this gets called?
.def("get_color_model", [](const morphablemodel::MorphableModel& m) { return m.get_color_model(); }, "Returns the PCA colour (albedo) model of this Morphable Model.")
; ;
return m.ptr(); morphablemodel_module.def("load_model", &morphablemodel::load_model, "Load a Morphable Model from a cereal::BinaryInputArchive (.bin) from the harddisk.");
return eos_module.ptr();
}; };
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