From 51fbf805bc9f83a2a045a24fbce799deaf314bca Mon Sep 17 00:00:00 2001 From: Tadas Baltrusaitis Date: Tue, 27 Mar 2018 16:26:26 +0100 Subject: [PATCH] Adapting to the case where no AU models are present (e.g. due to licensing issues). --- lib/local/FaceAnalyser/src/FaceAnalyser.cpp | 39 ++++----- .../src/FaceAnalyserParameters.cpp | 6 +- lib/local/Utilities/src/Visualizer.cpp | 80 ++++++++++--------- 3 files changed, 67 insertions(+), 58 deletions(-) diff --git a/lib/local/FaceAnalyser/src/FaceAnalyser.cpp b/lib/local/FaceAnalyser/src/FaceAnalyser.cpp index 1d579fc..6c7f92b 100644 --- a/lib/local/FaceAnalyser/src/FaceAnalyser.cpp +++ b/lib/local/FaceAnalyser/src/FaceAnalyser.cpp @@ -1224,25 +1224,28 @@ void FaceAnalyser::ReadRegressor(std::string fname, const vector& au_nam { ifstream regressor_stream(fname.c_str(), ios::in | ios::binary); - // First read the input type - int regressor_type; - regressor_stream.read((char*)®ressor_type, 4); - - if(regressor_type == SVR_appearance_static_linear) + if(regressor_stream.is_open()) { - AU_SVR_static_appearance_lin_regressors.Read(regressor_stream, au_names); - } - else if(regressor_type == SVR_appearance_dynamic_linear) - { - AU_SVR_dynamic_appearance_lin_regressors.Read(regressor_stream, au_names); - } - else if(regressor_type == SVM_linear_stat) - { - AU_SVM_static_appearance_lin.Read(regressor_stream, au_names); - } - else if(regressor_type == SVM_linear_dyn) - { - AU_SVM_dynamic_appearance_lin.Read(regressor_stream, au_names); + // First read the input type + int regressor_type; + regressor_stream.read((char*)®ressor_type, 4); + + if(regressor_type == SVR_appearance_static_linear) + { + AU_SVR_static_appearance_lin_regressors.Read(regressor_stream, au_names); + } + else if(regressor_type == SVR_appearance_dynamic_linear) + { + AU_SVR_dynamic_appearance_lin_regressors.Read(regressor_stream, au_names); + } + else if(regressor_type == SVM_linear_stat) + { + AU_SVM_static_appearance_lin.Read(regressor_stream, au_names); + } + else if(regressor_type == SVM_linear_dyn) + { + AU_SVM_dynamic_appearance_lin.Read(regressor_stream, au_names); + } } } diff --git a/lib/local/FaceAnalyser/src/FaceAnalyserParameters.cpp b/lib/local/FaceAnalyser/src/FaceAnalyserParameters.cpp index 9c4db3b..b9ef8d1 100644 --- a/lib/local/FaceAnalyser/src/FaceAnalyserParameters.cpp +++ b/lib/local/FaceAnalyser/src/FaceAnalyserParameters.cpp @@ -182,7 +182,7 @@ void FaceAnalyserParameters::init() } else { - std::cout << "Could not find the AU detection model to load" << std::endl; + std::cout << "Could not find the face analysis module to load" << std::endl; } orientation_bins = vector(); @@ -226,7 +226,7 @@ void FaceAnalyserParameters::OptimizeForVideos() } else { - std::cout << "Could not find the AU detection model to load" << std::endl; + std::cout << "Could not find the face analysis module to load" << std::endl; } } @@ -256,7 +256,7 @@ void FaceAnalyserParameters::OptimizeForImages() } else { - std::cout << "Could not find the AU detection model to load" << std::endl; + std::cout << "Could not find the face analysis module to load" << std::endl; } } diff --git a/lib/local/Utilities/src/Visualizer.cpp b/lib/local/Utilities/src/Visualizer.cpp index c5dc183..d412c37 100644 --- a/lib/local/Utilities/src/Visualizer.cpp +++ b/lib/local/Utilities/src/Visualizer.cpp @@ -234,48 +234,54 @@ void Visualizer::SetObservationPose(const cv::Vec6d& pose, double confidence) void Visualizer::SetObservationActionUnits(const std::vector >& au_intensities, const std::vector >& au_occurences) { - const int NB_AUS = 17; + if(au_intensities.size() > 0 || au_occurences.size() > 0) + { + const int NB_AUS = 17; - const int AU_TRACKBAR_LENGTH = 400; - const int AU_TRACKBAR_HEIGHT = 10; + const int AU_TRACKBAR_LENGTH = 400; + const int AU_TRACKBAR_HEIGHT = 10; - const int MARGIN_X = 185; - const int MARGIN_Y = 10; + const int MARGIN_X = 185; + const int MARGIN_Y = 10; - action_units_image = cv::Mat(NB_AUS * (AU_TRACKBAR_HEIGHT + 10) + MARGIN_Y * 2, AU_TRACKBAR_LENGTH + MARGIN_X, CV_8UC3, cv::Scalar(255,255,255)); + action_units_image = cv::Mat(NB_AUS * (AU_TRACKBAR_HEIGHT + 10) + MARGIN_Y * 2, AU_TRACKBAR_LENGTH + MARGIN_X, CV_8UC3, cv::Scalar(255,255,255)); - std::map> aus; + std::map> aus; - // first, prepare a mapping "AU name" -> { present, intensity } - for (size_t idx = 0; idx < au_intensities.size(); idx++) { - aus[au_intensities[idx].first] = std::make_pair(au_occurences[idx].second != 0, au_intensities[idx].second); - } + // first, prepare a mapping "AU name" -> { present, intensity } + for (size_t idx = 0; idx < au_intensities.size(); idx++) { + aus[au_intensities[idx].first] = std::make_pair(au_occurences[idx].second != 0, au_intensities[idx].second); + } - // then, build the graph - size_t idx = 0; - for (auto& au : aus) { - std::string name = au.first; - bool present = au.second.first; - double intensity = au.second.second; + // then, build the graph + size_t idx = 0; + for (auto& au : aus) + { + std::string name = au.first; + bool present = au.second.first; + double intensity = au.second.second; - auto offset = MARGIN_Y + idx * (AU_TRACKBAR_HEIGHT + 10); - std::ostringstream au_i; - au_i << std::setprecision(2) << std::setw(4) << std::fixed << intensity; - cv::putText(action_units_image, name, cv::Point(10, offset + 10), CV_FONT_HERSHEY_SIMPLEX, 0.5, CV_RGB(present ? 0 : 200, 0, 0), 1, CV_AA); - cv::putText(action_units_image, AUS_DESCRIPTION.at(name), cv::Point(55, offset + 10), CV_FONT_HERSHEY_SIMPLEX, 0.3, CV_RGB(0, 0, 0), 1, CV_AA); + auto offset = MARGIN_Y + idx * (AU_TRACKBAR_HEIGHT + 10); + std::ostringstream au_i; + au_i << std::setprecision(2) << std::setw(4) << std::fixed << intensity; + cv::putText(action_units_image, name, cv::Point(10, offset + 10), CV_FONT_HERSHEY_SIMPLEX, 0.5, CV_RGB(present ? 0 : 200, 0, 0), 1, CV_AA); + cv::putText(action_units_image, AUS_DESCRIPTION.at(name), cv::Point(55, offset + 10), CV_FONT_HERSHEY_SIMPLEX, 0.3, CV_RGB(0, 0, 0), 1, CV_AA); - if(present) { - cv::putText(action_units_image, au_i.str(), cv::Point(160, offset + 10), CV_FONT_HERSHEY_SIMPLEX, 0.3, CV_RGB(0, 100, 0), 1, CV_AA); - cv::rectangle(action_units_image, cv::Point(MARGIN_X, offset), - cv::Point(MARGIN_X + AU_TRACKBAR_LENGTH * intensity/5, offset + AU_TRACKBAR_HEIGHT), - cv::Scalar(128,128,128), - CV_FILLED); - } - else { - cv::putText(action_units_image, "0.00", cv::Point(160, offset + 10), CV_FONT_HERSHEY_SIMPLEX, 0.3, CV_RGB(0, 0, 0), 1, CV_AA); - } - idx++; - } + if(present) + { + cv::putText(action_units_image, au_i.str(), cv::Point(160, offset + 10), CV_FONT_HERSHEY_SIMPLEX, 0.3, CV_RGB(0, 100, 0), 1, CV_AA); + cv::rectangle(action_units_image, cv::Point(MARGIN_X, offset), + cv::Point(MARGIN_X + AU_TRACKBAR_LENGTH * intensity/5, offset + AU_TRACKBAR_HEIGHT), + cv::Scalar(128,128,128), + CV_FILLED); + } + else + { + cv::putText(action_units_image, "0.00", cv::Point(160, offset + 10), CV_FONT_HERSHEY_SIMPLEX, 0.3, CV_RGB(0, 0, 0), 1, CV_AA); + } + idx++; + } + } } // Eye gaze infomration drawing, first of eye landmarks then of gaze @@ -374,14 +380,14 @@ char Visualizer::ShowObservation() { cv::imshow("hog", hog_image); } - if (vis_aus) + if (vis_aus && !action_units_image.empty()) { - cv::namedWindow("action units", cv::WindowFlags::WINDOW_NORMAL); + cv::namedWindow("action units", cv::WindowFlags::WINDOW_KEEPRATIO); cv::imshow("action units", action_units_image); } if (vis_track) { - cv::namedWindow("tracking result", cv::WindowFlags::WINDOW_NORMAL); + cv::namedWindow("tracking result", cv::WindowFlags::WINDOW_KEEPRATIO); cv::imshow("tracking result", captured_image); } return cv::waitKey(1);