mirror of
https://gitcode.com/gh_mirrors/ope/OpenFace.git
synced 2026-09-03 05:47:46 +00:00
Simplifying the code a bit with moving to floats instead of doubles for likelihoods
This commit is contained in:
@@ -87,7 +87,7 @@ double fps_tracker = -1.0;
|
||||
int64 t0 = 0;
|
||||
|
||||
// Visualising the results
|
||||
void visualise_tracking(cv::Mat& captured_image, const LandmarkDetector::CLNF& face_model, const LandmarkDetector::FaceModelParameters& det_parameters, cv::Point3f gazeDirection0, cv::Point3f gazeDirection1, int frame_count, double fx, double fy, double cx, double cy)
|
||||
void visualise_tracking(cv::Mat& captured_image, const LandmarkDetector::CLNF& face_model, const LandmarkDetector::FaceModelParameters& det_parameters, cv::Point3f gazeDirection0, cv::Point3f gazeDirection1, int frame_count, float fx, float fy, float cx, float cy)
|
||||
{
|
||||
|
||||
// Drawing the facial landmarks on the face and the bounding box around it if tracking is successful and initialised
|
||||
|
||||
@@ -70,10 +70,10 @@ namespace LandmarkDetector
|
||||
|
||||
// Return the current estimate of the head pose in world coordinates with camera at origin (0,0,0)
|
||||
// The format returned is [Tx, Ty, Tz, Eul_x, Eul_y, Eul_z]
|
||||
cv::Vec6d GetPose(const CLNF& clnf_model, double fx, double fy, double cx, double cy);
|
||||
cv::Vec6d GetPose(const CLNF& clnf_model, float fx, float fy, float cx, float cy);
|
||||
|
||||
// Return the current estimate of the head pose in world coordinates with camera at origin (0,0,0), but with rotation representing if the head is looking at the camera
|
||||
// The format returned is [Tx, Ty, Tz, Eul_x, Eul_y, Eul_z]
|
||||
cv::Vec6d GetPoseWRTCamera(const CLNF& clnf_model, double fx, double fy, double cx, double cy);
|
||||
cv::Vec6d GetPoseWRTCamera(const CLNF& clnf_model, float fx, float fy, float cx, float cy);
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -123,8 +123,8 @@ public:
|
||||
cv::Mat_<double> detected_landmarks;
|
||||
|
||||
// The landmark detection likelihoods (combined and per patch expert)
|
||||
double model_likelihood;
|
||||
cv::Mat_<double> landmark_likelihoods;
|
||||
float model_likelihood;
|
||||
cv::Mat_<float> landmark_likelihoods;
|
||||
|
||||
// Keeping track of how many frames the tracker has failed in so far when tracking in videos
|
||||
// This is useful for knowing when to initialise and reinitialise tracking
|
||||
@@ -194,8 +194,8 @@ private:
|
||||
void NonVectorisedMeanShift_precalc_kde(cv::Mat_<float>& out_mean_shifts, const vector<cv::Mat_<float> >& patch_expert_responses, const cv::Mat_<float> &dxs, const cv::Mat_<float> &dys, int resp_size, float a, int scale, int view_id, map<int, cv::Mat_<float> >& mean_shifts);
|
||||
|
||||
// The actual model optimisation (update step), returns the model likelihood
|
||||
double NU_RLMS(cv::Vec6d& final_global, cv::Mat_<double>& final_local, const vector<cv::Mat_<float> >& patch_expert_responses, const cv::Vec6d& initial_global, const cv::Mat_<double>& initial_local,
|
||||
const cv::Mat_<double>& base_shape, const cv::Matx22d& sim_img_to_ref, const cv::Matx22f& sim_ref_to_img, int resp_size, int view_idx, bool rigid, int scale, cv::Mat_<double>& landmark_lhoods, const FaceModelParameters& parameters, bool compute_lhood);
|
||||
float NU_RLMS(cv::Vec6d& final_global, cv::Mat_<double>& final_local, const vector<cv::Mat_<float> >& patch_expert_responses, const cv::Vec6d& initial_global, const cv::Mat_<double>& initial_local,
|
||||
const cv::Mat_<double>& base_shape, const cv::Matx22d& sim_img_to_ref, const cv::Matx22f& sim_ref_to_img, int resp_size, int view_idx, bool rigid, int scale, cv::Mat_<float>& landmark_lhoods, const FaceModelParameters& parameters, bool compute_lhood);
|
||||
|
||||
// Generating the weight matrix for the Weighted least squares
|
||||
void GetWeightMatrix(cv::Mat_<float>& WeightMatrix, int scale, int view_id, const FaceModelParameters& parameters);
|
||||
|
||||
@@ -51,7 +51,7 @@ using namespace LandmarkDetector;
|
||||
// which is only correct close to the centre of the image
|
||||
// This method returns a corrected pose estimate with respect to world coordinates with camera at origin (0,0,0)
|
||||
// The format returned is [Tx, Ty, Tz, Eul_x, Eul_y, Eul_z]
|
||||
cv::Vec6d LandmarkDetector::GetPose(const CLNF& clnf_model, double fx, double fy, double cx, double cy)
|
||||
cv::Vec6d LandmarkDetector::GetPose(const CLNF& clnf_model, float fx, float fy, float cx, float cy)
|
||||
{
|
||||
if (!clnf_model.detected_landmarks.empty() && clnf_model.params_global[0] != 0)
|
||||
{
|
||||
@@ -97,7 +97,7 @@ cv::Vec6d LandmarkDetector::GetPose(const CLNF& clnf_model, double fx, double fy
|
||||
// Getting a head pose estimate from the currently detected landmarks, with appropriate correction due to perspective projection
|
||||
// This method returns a corrected pose estimate with respect to a point camera (NOTE not the world coordinates), which is useful to find out if the person is looking at a camera
|
||||
// The format returned is [Tx, Ty, Tz, Eul_x, Eul_y, Eul_z]
|
||||
cv::Vec6d LandmarkDetector::GetPoseWRTCamera(const CLNF& clnf_model, double fx, double fy, double cx, double cy)
|
||||
cv::Vec6d LandmarkDetector::GetPoseWRTCamera(const CLNF& clnf_model, float fx, float fy, float cx, float cy)
|
||||
{
|
||||
if (!clnf_model.detected_landmarks.empty() && clnf_model.params_global[0] != 0)
|
||||
{
|
||||
@@ -310,7 +310,7 @@ bool LandmarkDetector::DetectLandmarksInVideo(const cv::Mat &image, CLNF& clnf_m
|
||||
cv::Mat_<double> params_local_init = clnf_model.params_local.clone();
|
||||
double likelihood_init = clnf_model.model_likelihood;
|
||||
cv::Mat_<double> detected_landmarks_init = clnf_model.detected_landmarks.clone();
|
||||
cv::Mat_<double> landmark_likelihoods_init = clnf_model.landmark_likelihoods.clone();
|
||||
cv::Mat_<float> landmark_likelihoods_init = clnf_model.landmark_likelihoods.clone();
|
||||
|
||||
// Use the detected bounding box and empty local parameters
|
||||
clnf_model.params_local.setTo(0);
|
||||
@@ -402,7 +402,7 @@ bool DetectLandmarksInImageMultiHypBasic(const cv::Mat_<uchar> &grayscale_image,
|
||||
cv::Vec6d best_global_parameters;
|
||||
cv::Mat_<double> best_local_parameters;
|
||||
cv::Mat_<double> best_detected_landmarks;
|
||||
cv::Mat_<double> best_landmark_likelihoods;
|
||||
cv::Mat_<float> best_landmark_likelihoods;
|
||||
bool best_success;
|
||||
|
||||
// The hierarchical model parameters
|
||||
@@ -410,7 +410,7 @@ bool DetectLandmarksInImageMultiHypBasic(const cv::Mat_<uchar> &grayscale_image,
|
||||
vector<cv::Vec6d> best_global_parameters_h(clnf_model.hierarchical_models.size());
|
||||
vector<cv::Mat_<double>> best_local_parameters_h(clnf_model.hierarchical_models.size());
|
||||
vector<cv::Mat_<double>> best_detected_landmarks_h(clnf_model.hierarchical_models.size());
|
||||
vector<cv::Mat_<double>> best_landmark_likelihoods_h(clnf_model.hierarchical_models.size());
|
||||
vector<cv::Mat_<float>> best_landmark_likelihoods_h(clnf_model.hierarchical_models.size());
|
||||
|
||||
for (size_t hypothesis = 0; hypothesis < rotation_hypotheses.size(); ++hypothesis)
|
||||
{
|
||||
@@ -504,7 +504,7 @@ bool DetectLandmarksInImageMultiHypEarlyTerm(const cv::Mat_<uchar> &grayscale_im
|
||||
bool success = false;
|
||||
|
||||
// Keeping track of converges
|
||||
vector<double> likelihoods;
|
||||
vector<float> likelihoods;
|
||||
vector<cv::Vec6d> global_parameters;
|
||||
vector<cv::Mat_<double>> local_parameters;
|
||||
|
||||
@@ -524,7 +524,7 @@ bool DetectLandmarksInImageMultiHypEarlyTerm(const cv::Mat_<uchar> &grayscale_im
|
||||
// Perform landmark detection in first scale
|
||||
clnf_model.DetectLandmarks(grayscale_image, params);
|
||||
|
||||
double lhood = clnf_model.model_likelihood * clnf_model.patch_experts.early_term_weights[clnf_model.view_used] + clnf_model.patch_experts.early_term_biases[clnf_model.view_used];
|
||||
float lhood = clnf_model.model_likelihood * clnf_model.patch_experts.early_term_weights[clnf_model.view_used] + clnf_model.patch_experts.early_term_biases[clnf_model.view_used];
|
||||
|
||||
// If likelihood higher than cutoff continue on this model
|
||||
if (lhood > clnf_model.patch_experts.early_term_cutoffs[clnf_model.view_used])
|
||||
@@ -550,11 +550,11 @@ bool DetectLandmarksInImageMultiHypEarlyTerm(const cv::Mat_<uchar> &grayscale_im
|
||||
{
|
||||
|
||||
// Store the current best estimate
|
||||
double best_likelihood;
|
||||
float best_likelihood;
|
||||
cv::Vec6d best_global_parameters;
|
||||
cv::Mat_<double> best_local_parameters;
|
||||
cv::Mat_<double> best_detected_landmarks;
|
||||
cv::Mat_<double> best_landmark_likelihoods;
|
||||
cv::Mat_<float> best_landmark_likelihoods;
|
||||
bool best_success;
|
||||
|
||||
// The hierarchical model parameters
|
||||
@@ -562,7 +562,7 @@ bool DetectLandmarksInImageMultiHypEarlyTerm(const cv::Mat_<uchar> &grayscale_im
|
||||
vector<cv::Vec6d> best_global_parameters_h(clnf_model.hierarchical_models.size());
|
||||
vector<cv::Mat_<double>> best_local_parameters_h(clnf_model.hierarchical_models.size());
|
||||
vector<cv::Mat_<double>> best_detected_landmarks_h(clnf_model.hierarchical_models.size());
|
||||
vector<cv::Mat_<double>> best_landmark_likelihoods_h(clnf_model.hierarchical_models.size());
|
||||
vector<cv::Mat_<float>> best_landmark_likelihoods_h(clnf_model.hierarchical_models.size());
|
||||
|
||||
// Sort the likelihoods and pick the best top 3 models
|
||||
vector<size_t> indices = sort_indexes(likelihoods);
|
||||
|
||||
@@ -938,8 +938,8 @@ void CLNF::GetWeightMatrix(cv::Mat_<float>& WeightMatrix, int scale, int view_id
|
||||
}
|
||||
|
||||
//=============================================================================
|
||||
double CLNF::NU_RLMS(cv::Vec6d& final_global, cv::Mat_<double>& final_local, const vector<cv::Mat_<float> >& patch_expert_responses, const cv::Vec6d& initial_global, const cv::Mat_<double>& initial_local,
|
||||
const cv::Mat_<double>& base_shape, const cv::Matx22d& sim_img_to_ref, const cv::Matx22f& sim_ref_to_img, int resp_size, int view_id, bool rigid, int scale, cv::Mat_<double>& landmark_lhoods,
|
||||
float CLNF::NU_RLMS(cv::Vec6d& final_global, cv::Mat_<double>& final_local, const vector<cv::Mat_<float> >& patch_expert_responses, const cv::Vec6d& initial_global, const cv::Mat_<double>& initial_local,
|
||||
const cv::Mat_<double>& base_shape, const cv::Matx22d& sim_img_to_ref, const cv::Matx22f& sim_ref_to_img, int resp_size, int view_id, bool rigid, int scale, cv::Mat_<float>& landmark_lhoods,
|
||||
const FaceModelParameters& parameters, bool compute_lhood)
|
||||
{
|
||||
|
||||
@@ -1088,11 +1088,11 @@ double CLNF::NU_RLMS(cv::Vec6d& final_global, cv::Mat_<double>& final_local, con
|
||||
}
|
||||
|
||||
// compute the log likelihood
|
||||
double loglhood = 0;
|
||||
float loglhood = 0;
|
||||
|
||||
if(compute_lhood)
|
||||
{
|
||||
landmark_lhoods = cv::Mat_<double>(n, 1, -1e8);
|
||||
landmark_lhoods = cv::Mat_<float>(n, 1, -1e8);
|
||||
|
||||
for(int i = 0; i < n; i++)
|
||||
{
|
||||
@@ -1126,7 +1126,7 @@ double CLNF::NU_RLMS(cv::Vec6d& final_global, cv::Mat_<double>& final_local, con
|
||||
sum += v;
|
||||
}
|
||||
}
|
||||
landmark_lhoods.at<double>(i,0) = (double)sum;
|
||||
landmark_lhoods.at<float>(i,0) = sum;
|
||||
|
||||
// the offset is there for numerical stability
|
||||
loglhood += log(sum + 1e-8);
|
||||
|
||||
Reference in New Issue
Block a user