/////////////////////////////////////////////////////////////////////////////// // Copyright (C) 2017, Carnegie Mellon University and University of Cambridge, // all rights reserved. // // 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 // // * 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 2.0: Facial Behavior Analysis Toolkit // Tadas Baltrušaitis, Amir Zadeh, Yao Chong Lim, and Louis-Philippe Morency // in IEEE International Conference on Automatic Face and Gesture Recognition, 2018 // // Convolutional experts constrained local model for facial landmark detection. // A. Zadeh, T. Baltrušaitis, and Louis-Philippe Morency, // in Computer Vision and Pattern Recognition Workshops, 2017. // // Rendering of Eyes for Eye-Shape Registration and Gaze Estimation // Erroll Wood, Tadas Baltrušaitis, Xucong Zhang, Yusuke Sugano, Peter Robinson, and Andreas Bulling // in IEEE International. Conference on Computer Vision (ICCV), 2015 // // Cross-dataset learning and person-specific normalisation for automatic Action Unit detection // Tadas Baltrušaitis, Marwa Mahmoud, and Peter Robinson // in Facial Expression Recognition and Analysis Challenge, // IEEE International Conference on Automatic Face and Gesture Recognition, 2015 // /////////////////////////////////////////////////////////////////////////////// #ifndef __Patch_experts_h_ #define __Patch_experts_h_ // OpenCV includes #include #include "SVR_patch_expert.h" #include "CCNF_patch_expert.h" #include "CEN_patch_expert.h" #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 > > svr_expert_intensity; // The collection of LNF (CCNF) patch experts (for intensity images), the experts are laid out scale->view->landmark vector > > ccnf_expert_intensity; // The node connectivity for CCNF experts, at different window sizes and corresponding to separate edge features vector > > sigma_components; // The collection of CEN patch experts (for intensity images), the experts are laid out scale->view->landmark vector > > cen_expert_intensity; //Useful to pre-allocate data for im2col so that it is not allocated for every iteration and every patch vector< map > > preallocated_im2col; // The available scales for intensity patch experts vector patch_scaling; // The available views for the patch experts at every scale (in radians) vector > centers; // Landmark visibilities for each scale and view vector > > visibilities; cv::Mat_ mirror_inds; cv::Mat_ mirror_views; // Early termination calibration values, useful for CE-CLM model to speed up the multi-hypothesis setup vector early_term_weights; vector early_term_biases; vector early_term_cutoffs; // A default constructor Patch_experts(){;} // A copy constructor Patch_experts(const Patch_experts& other); // Returns the patch expert responses given a grayscale image. // 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 void Response(vector >& patch_expert_responses, cv::Matx22f& sim_ref_to_img, cv::Matx22f& sim_img_to_ref, const cv::Mat_& grayscale_image, const PDM& pdm, const cv::Vec6f& params_global, const cv::Mat_& params_local, int window_size, int scale); // Getting the best view associated with the current orientation int GetViewIdx(const cv::Vec6f& params_global, int scale) const; // The number of views at a particular scale inline int nViews(size_t scale = 0) const { return (int)centers[scale].size(); }; // Reading in all of the patch experts bool Read(vector intensity_svr_expert_locations, vector intensity_ccnf_expert_locations, vector intensity_cen_expert_locations, string early_term_loc = ""); private: bool Read_SVR_patch_experts(string expert_location, std::vector& centers, std::vector >& visibility, std::vector >& patches, double& scale); bool Read_CCNF_patch_experts(string patchesFileLocation, std::vector& centers, std::vector >& visibility, std::vector >& patches, double& patchScaling); bool Read_CEN_patch_experts(string expert_location, std::vector& centers, std::vector >& visibility, std::vector >& patches, double& scale); // Helper for collecting visibilities std::vector Collect_visible_landmarks(vector > > visibilities, int scale, int view_id, int n); }; } #endif