2016-04-28 15:40:36 -04:00
///////////////////////////////////////////////////////////////////////////////
2017-05-08 21:36:23 -04:00
// Copyright (C) 2017, Carnegie Mellon University and University of Cambridge,
2016-04-28 15:40:36 -04:00
// all rights reserved.
//
2017-05-08 21:36:23 -04:00
// ACADEMIC OR NON-PROFIT ORGANIZATION NONCOMMERCIAL RESEARCH USE ONLY
//
// BY USING OR DOWNLOADING THE SOFTWARE, YOU ARE AGREEING TO THE TERMS OF THIS LICENSE AGREEMENT.
// IF YOU DO NOT AGREE WITH THESE TERMS, YOU MAY NOT USE OR DOWNLOAD THE SOFTWARE.
//
// License can be found in OpenFace-license.txt
2016-04-28 15:40:36 -04:00
//
// * Any publications arising from the use of this software, including but
// not limited to academic journal and conference publications, technical
// reports and manuals, must cite at least one of the following works:
//
// OpenFace: an open source facial behavior analysis toolkit
// Tadas Baltru<72> aitis, Peter Robinson, and Louis-Philippe Morency
// in IEEE Winter Conference on Applications of Computer Vision, 2016
//
// Rendering of Eyes for Eye-Shape Registration and Gaze Estimation
// Erroll Wood, Tadas Baltru<72> aitis, Xucong Zhang, Yusuke Sugano, Peter Robinson, and Andreas Bulling
// in IEEE International. Conference on Computer Vision (ICCV), 2015
//
// Cross-dataset learning and person-speci?c normalisation for automatic Action Unit detection
// Tadas Baltru<72> aitis, Marwa Mahmoud, and Peter Robinson
// in Facial Expression Recognition and Analysis Challenge,
// IEEE International Conference on Automatic Face and Gesture Recognition, 2015
//
// Constrained Local Neural Fields for robust facial landmark detection in the wild.
// Tadas Baltru<72> aitis, Peter Robinson, and Louis-Philippe Morency.
// in IEEE Int. Conference on Computer Vision Workshops, 300 Faces in-the-Wild Challenge, 2013.
//
///////////////////////////////////////////////////////////////////////////////
# ifndef __Patch_experts_h_
# define __Patch_experts_h_
// OpenCV includes
# include <opencv2/core/core.hpp>
# include "SVR_patch_expert.h"
# include "CCNF_patch_expert.h"
2018-05-06 08:19:09 +01:00
# include "CEN_patch_expert.h"
2016-04-28 15:40:36 -04:00
# include "PDM.h"
namespace LandmarkDetector
{
//===========================================================================
/**
Combined class for all of the patch experts
*/
class Patch_experts
{
public :
// The collection of SVR patch experts (for intensity/grayscale images), the experts are laid out scale->view->landmark
vector < vector < vector < Multi_SVR_patch_expert > > > svr_expert_intensity ;
// The collection of LNF (CCNF) patch experts (for intensity images), the experts are laid out scale->view->landmark
vector < vector < vector < CCNF_patch_expert > > > ccnf_expert_intensity ;
// The node connectivity for CCNF experts, at different window sizes and corresponding to separate edge features
vector < vector < cv : : Mat_ < float > > > sigma_components ;
2018-05-06 08:19:09 +01:00
// The collection of CEN patch experts (for intensity images), the experts are laid out scale->view->landmark
vector < vector < vector < CEN_patch_expert > > > cen_expert_intensity ;
//Useful to pre-allocate data for im2col so that it is not allocated for every iteration and every patch
vector < map < int , cv : : Mat_ < float > > > preallocated_im2col ;
2016-04-28 15:40:36 -04:00
// The available scales for intensity patch experts
vector < double > patch_scaling ;
// The available views for the patch experts at every scale (in radians)
vector < vector < cv : : Vec3d > > centers ;
// Landmark visibilities for each scale and view
vector < vector < cv : : Mat_ < int > > > visibilities ;
2018-05-06 08:19:09 +01:00
cv : : Mat_ < int > mirror_inds ;
cv : : Mat_ < int > mirror_views ;
// Early termination calibration values, useful for CE-CLM model to speed up the multi-hypothesis setup
vector < double > early_term_weights ;
vector < double > early_term_biases ;
vector < double > early_term_cutoffs ;
2016-04-28 15:40:36 -04:00
// A default constructor
Patch_experts ( ) { ; }
// A copy constructor
Patch_experts ( const Patch_experts & other ) ;
2017-08-01 17:11:02 -04:00
// Returns the patch expert responses given a grayscale image.
2016-04-28 15:40:36 -04:00
// Additionally returns the transform from the image coordinates to the response coordinates (and vice versa).
// The computation also requires the current landmark locations to compute response around, the PDM corresponding to the desired model, and the parameters describing its instance
// Also need to provide the size of the area of interest and the desired scale of analysis
2018-05-06 08:19:09 +01:00
void Response ( vector < cv : : Mat_ < float > > & patch_expert_responses , cv : : Matx22f & sim_ref_to_img , cv : : Matx22f & sim_img_to_ref , const cv : : Mat_ < uchar > & grayscale_image ,
const PDM & pdm , const cv : : Vec6f & params_global , const cv : : Mat_ < float > & params_local , int window_size , int scale ) ;
2016-04-28 15:40:36 -04:00
// Getting the best view associated with the current orientation
2018-05-06 08:19:09 +01:00
int GetViewIdx ( const cv : : Vec6f & params_global , int scale ) const ;
2016-04-28 15:40:36 -04:00
// The number of views at a particular scale
2016-09-06 12:32:33 -04:00
inline int nViews ( size_t scale = 0 ) const { return ( int ) centers [ scale ] . size ( ) ; } ;
2016-04-28 15:40:36 -04:00
// Reading in all of the patch experts
2018-05-06 08:19:09 +01:00
bool Read ( vector < string > intensity_svr_expert_locations , vector < string > intensity_ccnf_expert_locations , vector < string > intensity_cen_expert_locations , string early_term_loc = " " ) ;
2016-04-28 15:40:36 -04:00
private :
2018-05-06 08:19:09 +01:00
bool Read_SVR_patch_experts ( string expert_location , std : : vector < cv : : Vec3d > & centers , std : : vector < cv : : Mat_ < int > > & visibility , std : : vector < std : : vector < Multi_SVR_patch_expert > > & patches , double & scale ) ;
bool Read_CCNF_patch_experts ( string patchesFileLocation , std : : vector < cv : : Vec3d > & centers , std : : vector < cv : : Mat_ < int > > & visibility , std : : vector < std : : vector < CCNF_patch_expert > > & patches , double & patchScaling ) ;
bool Read_CEN_patch_experts ( string expert_location , std : : vector < cv : : Vec3d > & centers , std : : vector < cv : : Mat_ < int > > & visibility , std : : vector < std : : vector < CEN_patch_expert > > & patches , double & scale ) ;
2016-04-28 15:40:36 -04:00
2018-05-06 08:19:09 +01:00
// Helper for collecting visibilities
std : : vector < int > Collect_visible_landmarks ( vector < vector < cv : : Mat_ < int > > > visibilities , int scale , int view_id , int n ) ;
2016-04-28 15:40:36 -04:00
} ;
}
# endif