Commit ac886b5b authored by Richard Torenvliet's avatar Richard Torenvliet

Merge branch 'multi_image_fit_devel' into multi-frame-richard

parents d533426a 5ffddcd4
...@@ -30,6 +30,11 @@ add_executable(fit-model fit-model.cpp) ...@@ -30,6 +30,11 @@ add_executable(fit-model fit-model.cpp)
target_link_libraries(fit-model eos ${OpenCV_LIBS} ${Boost_LIBRARIES}) target_link_libraries(fit-model eos ${OpenCV_LIBS} ${Boost_LIBRARIES})
target_link_libraries(fit-model "$<$<CXX_COMPILER_ID:GNU>:-pthread>$<$<CXX_COMPILER_ID:Clang>:-pthreads>") target_link_libraries(fit-model "$<$<CXX_COMPILER_ID:GNU>:-pthread>$<$<CXX_COMPILER_ID:Clang>:-pthreads>")
# Model fitting example that fits orthographic camera, shape, blendshapes, and contours to multiple images:
add_executable(fit-model-multi fit-model-multi.cpp)
target_link_libraries(fit-model-multi eos ${OpenCV_LIBS} ${Boost_LIBRARIES})
target_link_libraries(fit-model-multi "$<$<CXX_COMPILER_ID:GNU>:-pthread>$<$<CXX_COMPILER_ID:Clang>:-pthreads>")
# Generate random samples from the model: # Generate random samples from the model:
add_executable(generate-obj generate-obj.cpp) add_executable(generate-obj generate-obj.cpp)
target_link_libraries(generate-obj eos ${OpenCV_LIBS} ${Boost_LIBRARIES}) target_link_libraries(generate-obj eos ${OpenCV_LIBS} ${Boost_LIBRARIES})
...@@ -42,6 +47,7 @@ target_link_libraries(fit-model-multi-frame "$<$<CXX_COMPILER_ID:GNU>:-pthread>$ ...@@ -42,6 +47,7 @@ target_link_libraries(fit-model-multi-frame "$<$<CXX_COMPILER_ID:GNU>:-pthread>$
# Install these targets: # Install these targets:
install(TARGETS fit-model-simple DESTINATION bin) install(TARGETS fit-model-simple DESTINATION bin)
install(TARGETS fit-model DESTINATION bin) install(TARGETS fit-model DESTINATION bin)
install(TARGETS fit-model-multi DESTINATION bin)
install(TARGETS generate-obj DESTINATION bin) install(TARGETS generate-obj DESTINATION bin)
install(TARGETS fit-model-multi-frame DESTINATION bin) install(TARGETS fit-model-multi-frame DESTINATION bin)
install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/data DESTINATION bin) install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/data DESTINATION bin)
......
This diff is collapsed.
This diff is collapsed.
/*
* eos - A 3D Morphable Model fitting library written in modern C++11/14.
*
* File: include/eos/fitting/multiframe_linear.hpp
*
* Copyright 2016 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 MULTIFRAME_LINEAR_PATRIK_HPP_
#define MULTIFRAME_LINEAR_PATRIK_HPP_
#include "eos/morphablemodel/MorphableModel.hpp"
#include "eos/morphablemodel/Blendshape.hpp"
#include "eos/fitting/linear_shape_fitting.hpp"
#include "eos/fitting/blendshape_fitting.hpp"
#include "eos/fitting/contour_correspondence.hpp"
#include "eos/fitting/nonlinear_camera_estimation.hpp"
//#include "glm/gtc/matrix_transform.hpp"
#include "opencv2/core/core.hpp"
#include <vector>
#include <iostream>
namespace eos {
namespace fitting {
/**
*
* @param morphable_model
* @param affine_camera_matrix
* @param landmarks
* @param vertex_ids
* @param base_face
* @param lambda
* @param num_coefficients_to_fit
* @param detector_standard_deviation
* @param model_standard_deviation
*
* @return
*/
inline std::vector<float> fit_shape_to_landmarks_linear_multi(
morphablemodel::MorphableModel morphable_model,
std::vector <cv::Mat> affine_camera_matrix,
std::vector <std::vector<cv::Vec2f>> landmarks,
std::vector <std::vector<int>> vertex_ids,
std::vector <cv::Mat> base_face = std::vector<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>()) {
}
}
}
This diff is collapsed.
...@@ -26,9 +26,10 @@ ...@@ -26,9 +26,10 @@
#include "eos/core/Mesh.hpp" #include "eos/core/Mesh.hpp"
#include "eos/morphablemodel/io/mat_cerealisation.hpp" #include "eos/morphablemodel/io/eigen_cerealisation.hpp"
#include "cereal/cereal.hpp" #include "cereal/cereal.hpp"
#include "cereal/access.hpp" #include "cereal/access.hpp"
#include "cereal/types/array.hpp"
#include "cereal/types/vector.hpp" #include "cereal/types/vector.hpp"
#include "cereal/archives/binary.hpp" #include "cereal/archives/binary.hpp"
...@@ -41,6 +42,7 @@ ...@@ -41,6 +42,7 @@
#include <vector> #include <vector>
#include <array> #include <array>
#include <cstdint> #include <cstdint>
#include <fstream>
namespace eos { namespace eos {
namespace morphablemodel { namespace morphablemodel {
......
...@@ -26,6 +26,7 @@ ...@@ -26,6 +26,7 @@
#include "cereal/access.hpp" #include "cereal/access.hpp"
#include "cereal/types/array.hpp" #include "cereal/types/array.hpp"
#include "cereal/types/vector.hpp" #include "cereal/types/vector.hpp"
#include "cereal/archives/binary.hpp"
#include "Eigen/Core" #include "Eigen/Core"
...@@ -34,6 +35,7 @@ ...@@ -34,6 +35,7 @@
#include <array> #include <array>
#include <random> #include <random>
#include <cassert> #include <cassert>
#include <fstream>
namespace eos { namespace eos {
namespace morphablemodel { namespace morphablemodel {
...@@ -57,7 +59,7 @@ public: ...@@ -57,7 +59,7 @@ public:
PcaModel() = default; PcaModel() = default;
/** /**
* Construct a PCA model from given mean, normalised PCA basis, eigenvalues * Construct a PCA model from given mean, orthonormal PCA basis, eigenvalues
* and triangle list. * and triangle list.
* *
* See the documentation of the member variables for how the data should * See the documentation of the member variables for how the data should
...@@ -292,6 +294,45 @@ private: ...@@ -292,6 +294,45 @@ private:
}; };
}; };
/**
* Helper method to load a PCA model from
* a cereal::BinaryInputArchive from the harddisk.
*
* Usually, morphablemodel::load_model(std::string) should be used to directly
* load a MorphableModel. This function can be useful when it is necessary to just
* load a PCA model.
*
* @param[in] filename Filename to a model.
* @return The loaded PCA model.
* @throw std::runtime_error When the file given in \c filename fails to be opened (most likely because the file doesn't exist).
*/
inline PcaModel load_pca_model(std::string filename)
{
PcaModel model;
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(model);
return model;
};
/**
* Helper method to save a PCA model to the
* harddrive as cereal::BinaryOutputArchive.
*
* @param[in] model The model to be saved.
* @param[in] filename Filename for the model.
*/
inline void save_pca_model(PcaModel model, std::string filename)
{
std::ofstream file(filename, std::ios::binary);
cereal::BinaryOutputArchive output_archive(file);
output_archive(model);
};
/** /**
* Takes an orthonormal PCA basis matrix (a matrix consisting * Takes an orthonormal PCA basis matrix (a matrix consisting
......
...@@ -81,8 +81,8 @@ PYBIND11_PLUGIN(eos) { ...@@ -81,8 +81,8 @@ PYBIND11_PLUGIN(eos) {
* Bindings for the eos::morphablemodel namespace: * Bindings for the eos::morphablemodel namespace:
* - PcaModel * - PcaModel
* - MorphableModel * - MorphableModel
* - load_model() * - load_model(), save_model()
* - save_model() * - load_pca_model(), save_pca_model()
*/ */
py::module morphablemodel_module = eos_module.def_submodule("morphablemodel", "Functionality to represent a Morphable Model, its PCA models, and functions to load models and blendshapes."); py::module morphablemodel_module = eos_module.def_submodule("morphablemodel", "Functionality to represent a Morphable Model, its PCA models, and functions to load models and blendshapes.");
...@@ -107,10 +107,13 @@ PYBIND11_PLUGIN(eos) { ...@@ -107,10 +107,13 @@ PYBIND11_PLUGIN(eos) {
.def("get_mean", &morphablemodel::MorphableModel::get_mean, "Returns the mean of the shape- and colour model as a Mesh.") .def("get_mean", &morphablemodel::MorphableModel::get_mean, "Returns the mean of the shape- and colour model as a Mesh.")
.def("draw_sample", (core::Mesh(morphablemodel::MorphableModel::*)(std::vector<float>, std::vector<float>) const)&morphablemodel::MorphableModel::draw_sample, "Returns a sample from the model with the given shape- and colour PCA coefficients.", py::arg("shape_coefficients"), py::arg("color_coefficients")) .def("draw_sample", (core::Mesh(morphablemodel::MorphableModel::*)(std::vector<float>, std::vector<float>) const)&morphablemodel::MorphableModel::draw_sample, "Returns a sample from the model with the given shape- and colour PCA coefficients.", py::arg("shape_coefficients"), py::arg("color_coefficients"))
.def("has_color_model", &morphablemodel::MorphableModel::has_color_model, "Returns true if this Morphable Model contains a colour model, and false if it is a shape-only model.") .def("has_color_model", &morphablemodel::MorphableModel::has_color_model, "Returns true if this Morphable Model contains a colour model, and false if it is a shape-only model.")
.def("get_texture_coordinates", &morphablemodel::MorphableModel::get_texture_coordinates, "Returns the texture coordinates for all the vertices in the model.")
; ;
morphablemodel_module.def("load_model", &morphablemodel::load_model, "Load a Morphable Model from a cereal::BinaryInputArchive (.bin) from the harddisk.", py::arg("filename")); morphablemodel_module.def("load_model", &morphablemodel::load_model, "Load a Morphable Model from a cereal::BinaryInputArchive (.bin) from the harddisk.", py::arg("filename"));
morphablemodel_module.def("save_model", &morphablemodel::save_model, "Save a Morphable Model as cereal::BinaryOutputArchive.", py::arg("model"), py::arg("filename")); morphablemodel_module.def("save_model", &morphablemodel::save_model, "Save a Morphable Model as cereal::BinaryOutputArchive.", py::arg("model"), py::arg("filename"));
morphablemodel_module.def("load_pca_model", &morphablemodel::load_pca_model, "Load a PCA model from a cereal::BinaryInputArchive (.bin) from the harddisk.", py::arg("filename"));
morphablemodel_module.def("save_pca_model", &morphablemodel::save_pca_model, "Save a PCA model as cereal::BinaryOutputArchive.", py::arg("model"), py::arg("filename"));
/** /**
* - Blendshape * - Blendshape
......
...@@ -39,7 +39,7 @@ add_executable(accuracy-evaluation accuracy-evaluation.cpp) ...@@ -39,7 +39,7 @@ add_executable(accuracy-evaluation accuracy-evaluation.cpp)
target_link_libraries(accuracy-evaluation eos ${OpenCV_LIBS} ${Boost_LIBRARIES}) target_link_libraries(accuracy-evaluation eos ${OpenCV_LIBS} ${Boost_LIBRARIES})
target_link_libraries(accuracy-evaluation "$<$<CXX_COMPILER_ID:GNU>:-pthread>$<$<CXX_COMPILER_ID:Clang>:-pthreads>") target_link_libraries(accuracy-evaluation "$<$<CXX_COMPILER_ID:GNU>:-pthread>$<$<CXX_COMPILER_ID:Clang>:-pthreads>")
# install target: # Install targets:
install(TARGETS scm-to-cereal DESTINATION bin) install(TARGETS scm-to-cereal DESTINATION bin)
install(TARGETS bfm-binary-to-cereal DESTINATION bin) install(TARGETS bfm-binary-to-cereal DESTINATION bin)
install(TARGETS edgestruct-csv-to-json DESTINATION bin) install(TARGETS edgestruct-csv-to-json DESTINATION bin)
......
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