22#ifndef KEYFRAME_MERGING_HPP_
23#define KEYFRAME_MERGING_HPP_
25#include "eos/core/Image_opencv_interop.hpp"
26#include "eos/morphablemodel/Blendshape.hpp"
27#include "eos/morphablemodel/MorphableModel.hpp"
28#include "eos/render/texture_extraction.hpp"
29#include "eos/video/Keyframe.hpp"
33#include "opencv2/core/core.hpp"
34#include "opencv2/imgproc/imgproc.hpp"
67 const std::vector<morphablemodel::Blendshape>& blendshapes)
69 assert(keyframes.size() >= 1);
72 using Eigen::VectorXf;
76 for (
const auto& frame_data : keyframes)
78 const VectorXf shape =
81 Eigen::Map<const Eigen::VectorXf>(frame_data.fitting_result.expression_coefficients.data(),
82 frame_data.fitting_result.expression_coefficients.size());
87 frame_data.fitting_result.rendering_parameters, frame_data.frame.cols, frame_data.frame.rows);
89 render::TextureInterpolation::NearestNeighbour, 1024));
90 isomaps.push_back(isomap);
94 Mat r = Mat::zeros(isomaps[0].rows, isomaps[0].cols, CV_32FC1);
95 Mat g = Mat::zeros(isomaps[0].rows, isomaps[0].cols, CV_32FC1);
96 Mat b = Mat::zeros(isomaps[0].rows, isomaps[0].cols, CV_32FC1);
97 Mat accumulated_weight = Mat::zeros(isomaps[0].rows, isomaps[0].cols, CV_32FC1);
100 for (
auto&& isomap : isomaps)
102 vector<Mat> channels;
103 cv::split(isomap, channels);
110 Mat weighted_b, weighted_g, weighted_r;
112 cv::multiply(channels[0], channels[3], weighted_b, 1 / 255.0, CV_32FC1);
113 cv::multiply(channels[1], channels[3], weighted_g, 1 / 255.0, CV_32FC1);
114 cv::multiply(channels[2], channels[3], weighted_r, 1 / 255.0, CV_32FC1);
118 channels[3].convertTo(channels[3], CV_32FC1);
119 cv::add(accumulated_weight, channels[3] / 255.0f, accumulated_weight, cv::noArray(), CV_32FC1);
121 b = b.mul(1.0 / (accumulated_weight));
122 g = g.mul(1.0 / (accumulated_weight));
123 r = r.mul(1.0 / (accumulated_weight));
131 cv::merge(vector<Mat>{b, g, r}, merged_isomap);
132 merged_isomap.convertTo(merged_isomap, CV_8UC3);
133 return merged_isomap;
149 cv::Laplacian(image, laplacian, CV_64F);
151 cv::Scalar mu, sigma;
152 cv::meanStdDev(laplacian, mu, sigma);
154 const double focus_measure = sigma.val[0] * sigma.val[0];
155 return focus_measure;
A class representing a 3D Morphable Model, consisting of a shape- and colour (albedo) PCA model.
Definition: MorphableModel.hpp:73
const std::vector< std::array< double, 2 > > & get_texture_coordinates() const
Definition: MorphableModel.hpp:413
const PcaModel & get_shape_model() const
Definition: MorphableModel.hpp:125
Eigen::VectorXf draw_sample(RNG &engine, float sigma=1.0f) const
Definition: PcaModel.hpp:150
Image3u from_mat(const cv::Mat &image)
Definition: opencv_interop.hpp:98
Eigen::Matrix< float, 3, 4 > get_3x4_affine_camera_matrix(RenderingParameters params, int width, int height)
Creates a 3x4 affine camera matrix from given fitting parameters. The matrix transforms points direct...
Definition: RenderingParameters.hpp:337
Eigen::MatrixXf to_matrix(const std::vector< Blendshape > &blendshapes)
Copies the blendshapes into a matrix, with each column being a blendshape.
Definition: Blendshape.hpp:118
core::Mesh sample_to_mesh(const Eigen::VectorXf &shape_instance, const Eigen::VectorXf &color_instance, const std::vector< std::array< int, 3 > > &tvi, const std::vector< std::array< int, 3 > > &tci, const std::vector< std::array< double, 2 > > &texture_coordinates=std::vector< std::array< double, 2 > >(), const std::vector< std::array< int, 3 > > &texture_triangle_indices=std::vector< std::array< int, 3 > >())
Definition: MorphableModel.hpp:584
eos::core::Image4u extract_texture(const core::Mesh &mesh, Eigen::Matrix4f view_model_matrix, Eigen::Matrix4f projection_matrix, ProjectionType projection_type, const eos::core::Image4u &image, int texturemap_resolution=512)
Extracts the texture from the given image and returns a texture map.
Definition: texture_extraction.hpp:70
double variance_of_laplacian(const cv::Mat &image)
Computes the variance of laplacian of the given image or patch.
Definition: keyframe_merging.hpp:146
cv::Mat merge_weighted_mean(const std::vector< Keyframe< cv::Mat > > &keyframes, const morphablemodel::MorphableModel &morphable_model, const std::vector< morphablemodel::Blendshape > &blendshapes)
Extracts texture from each keyframe and merges them using a weighted mean.
Definition: keyframe_merging.hpp:65
Namespace containing all of eos's 3D model fitting functionality.
A keyframe selected by the fitting algorithm.
Definition: Keyframe.hpp:37