#ifndef EXPRESSION_FILTER #define EXPRESSION_FILTER #include "LikelihoodTable.h" #include "InputVector.h" #include #include // Number of expression state: 3 for now (absent, present, no-face) #define NUM_STATES 3 // Approximate number of frames processed per second */ #define FRAME_RATE 4 /* fps */ // Probability of the face detector correctly rejecting a non-face #define CORRECT_REJECTION_RATE (0.96) // Probability of the face detector INcorrectly rejecting a non-face #define FALSE_POSITIVE_RATE (1 - CORRECT_REJECTION_RATE) // Probability of the face detector missing a face when the expression is absent #define MISS_ABSENT_RATE (0.38) // Probability of the face detector finding a face when the expression is absent #define HIT_ABSENT_RATE (1 - MISS_ABSENT_RATE) // Probability of the face detector missing a face when the expression is present #define MISS_PRESENT_RATE (0.31) // Probability of the face detector finding a face when the expression is present #define HIT_PRESENT_RATE (1 - MISS_PRESENT_RATE) // Transition probabilities from each state to each other state. // P stands for present, A for absent, and NF for no-face // These should sum to 1 #define P_TO_P (1 - 1.0/(2 * FRAME_RATE)) #define P_TO_A (1.0/(4 * FRAME_RATE)) #define P_TO_NF (1.0/(4 * FRAME_RATE)) // These should sum to 1 #define A_TO_P (1.0/(4 * FRAME_RATE)) #define A_TO_A (1 - 1.0/(2 * FRAME_RATE)) #define A_TO_NF (1.0/(4 * FRAME_RATE)) // These should sum to 1 #define NF_TO_P (1.0/(20 * FRAME_RATE)) #define NF_TO_A (1.0/(20 * FRAME_RATE)) #define NF_TO_NF (1 - 1.0/(10 * FRAME_RATE)) // Order of states: PRESENT, ABSENT, NO_FACE const double PRIOR_PROBABILITIES[NUM_STATES] = { 0.5, 0.125, 0.375 }; const double TRANSITION_PROBABILITIES[NUM_STATES][NUM_STATES] = { { P_TO_P, P_TO_A, P_TO_NF }, { A_TO_P, A_TO_A, A_TO_NF }, { NF_TO_P, NF_TO_A, NF_TO_NF } }; class ExpressionFilter { public: typedef enum { PRESENT=0, ABSENT=1, NO_FACE=2 } expr_state; protected: double probabilities[NUM_STATES]; LikelihoodTable nonfaceLikelihoods, presentLikelihoods, absentLikelihoods; double TransitionProb (expr_state from, expr_state to); double CalcLikelihood (expr_state state, InputVector input); void NextTimeStepGivenLikelihoods (double likelihoods[NUM_STATES]); std::string BuildFileName( const std::string &dir, const std::string &prefix, int expression_num, bool face ); public: ExpressionFilter (int _expression_num, std::string dir = "" ); void NextTimeStep (InputVector input); double GetProbability (expr_state state); private: int expression_num; }; #endif