From 7bbca6c48c5799eb07d83827f04721379cef4f6d Mon Sep 17 00:00:00 2001 From: Tadas Baltrusaitis Date: Sun, 22 Oct 2017 20:55:47 +0100 Subject: [PATCH] Gaze output correction --- exe/FaceLandmarkImg/FaceLandmarkImg.cpp | 48 +++++++++++++------------ 1 file changed, 25 insertions(+), 23 deletions(-) diff --git a/exe/FaceLandmarkImg/FaceLandmarkImg.cpp b/exe/FaceLandmarkImg/FaceLandmarkImg.cpp index ced96ac..1f3bb63 100644 --- a/exe/FaceLandmarkImg/FaceLandmarkImg.cpp +++ b/exe/FaceLandmarkImg/FaceLandmarkImg.cpp @@ -169,7 +169,7 @@ void write_out_pose_landmarks(const string& outfeatures, const cv::Mat_& } } -void write_out_landmarks(const string& outfeatures, const LandmarkDetector::CLNF& clnf_model, const cv::Vec6d& pose, const cv::Point3f& gaze0, const cv::Point3f& gaze1, const cv::Vec2d gaze_angle, std::vector> au_intensities, std::vector> au_occurences) +void write_out_landmarks(const string& outfeatures, const LandmarkDetector::CLNF& clnf_model, const cv::Vec6d& pose, const cv::Point3f& gaze0, const cv::Point3f& gaze1, const cv::Vec2d gaze_angle, std::vector> au_intensities, std::vector> au_occurences, bool output_gaze) { create_directory_from_file(outfeatures); std::ofstream featuresFile; @@ -195,28 +195,30 @@ void write_out_landmarks(const string& outfeatures, const LandmarkDetector::CLNF featuresFile << pose[3] << " " << pose[4] << " " << pose[5] << endl; featuresFile << "}" << endl; - featuresFile << "gaze: dir_x_1, dir_y_1, dir_z_1, dir_x_2, dir_y_2, dir_z_2: " << endl; - featuresFile << "{" << endl; - featuresFile << gaze0.x << " " << gaze0.y << " " << gaze0.z << " " << gaze1.x << " " << gaze1.y << " " << gaze1.z << endl; - featuresFile << "}" << endl; - - featuresFile << "gaze: angle_x, angle_y: " << endl; - featuresFile << "{" << endl; - featuresFile << gaze_angle[0] << " " << gaze_angle[1] << endl; - featuresFile << "}" << endl; - - std::vector eye_landmark_points = LandmarkDetector::CalculateAllEyeLandmarks(clnf_model); - - featuresFile << "eye_lmks: " << eye_landmark_points.size() << endl; - featuresFile << "{" << endl; - - for (int i = 0; i < eye_landmark_points.size(); ++i) + if(output_gaze) { - // Use matlab format, so + 1 - featuresFile << eye_landmark_points[i].x + 1 << " " << eye_landmark_points[i].y + 1 << endl; - } - featuresFile << "}" << endl; + featuresFile << "gaze: dir_x_1, dir_y_1, dir_z_1, dir_x_2, dir_y_2, dir_z_2: " << endl; + featuresFile << "{" << endl; + featuresFile << gaze0.x << " " << gaze0.y << " " << gaze0.z << " " << gaze1.x << " " << gaze1.y << " " << gaze1.z << endl; + featuresFile << "}" << endl; + featuresFile << "gaze: angle_x, angle_y: " << endl; + featuresFile << "{" << endl; + featuresFile << gaze_angle[0] << " " << gaze_angle[1] << endl; + featuresFile << "}" << endl; + + std::vector eye_landmark_points = LandmarkDetector::CalculateAllEyeLandmarks(clnf_model); + + featuresFile << "eye_lmks: " << eye_landmark_points.size() << endl; + featuresFile << "{" << endl; + + for (int i = 0; i < eye_landmark_points.size(); ++i) + { + // Use matlab format, so + 1 + featuresFile << (eye_landmark_points[i].x + 1) << " " << (eye_landmark_points[i].y + 1) << endl; + } + featuresFile << "}" << endl; + } // Do the au intensities featuresFile << "au intensities: " << au_intensities.size() << endl; featuresFile << "{" << endl; @@ -495,7 +497,7 @@ int main (int argc, char **argv) boost::filesystem::path fname = out_feat_path.filename().replace_extension(""); boost::filesystem::path ext = out_feat_path.extension(); string outfeatures = dir.string() + preferredSlash + fname.string() + string(name) + ext.string(); - write_out_landmarks(outfeatures, clnf_model, headPose, gazeDirection0, gazeDirection1, gazeAngle, ActionUnits.first, ActionUnits.second); + write_out_landmarks(outfeatures, clnf_model, headPose, gazeDirection0, gazeDirection1, gazeAngle, ActionUnits.first, ActionUnits.second, det_parameters.track_gaze); } if (!output_pose_locations.empty()) @@ -600,7 +602,7 @@ int main (int argc, char **argv) if(!output_landmark_locations.empty()) { string outfeatures = output_landmark_locations.at(i); - write_out_landmarks(outfeatures, clnf_model, headPose, gazeDirection0, gazeDirection1, gazeAngle, ActionUnits.first, ActionUnits.second); + write_out_landmarks(outfeatures, clnf_model, headPose, gazeDirection0, gazeDirection1, gazeAngle, ActionUnits.first, ActionUnits.second, det_parameters.track_gaze); } // Writing out the detected landmarks