From 1159caba7542842e53a704ac89a97cfd5155ae0c Mon Sep 17 00:00:00 2001 From: Tadas Baltrusaitis Date: Sun, 5 Nov 2017 08:51:27 +0000 Subject: [PATCH] Output similarity aligned faces through recorder. --- exe/FeatureExtraction/FeatureExtraction.cpp | 24 ------------ lib/local/Recorder/include/RecorderOpenFace.h | 4 ++ lib/local/Recorder/src/RecorderOpenFace.cpp | 38 ++++++++++++++++++- 3 files changed, 41 insertions(+), 25 deletions(-) diff --git a/exe/FeatureExtraction/FeatureExtraction.cpp b/exe/FeatureExtraction/FeatureExtraction.cpp index bbcaec0..6f808a3 100644 --- a/exe/FeatureExtraction/FeatureExtraction.cpp +++ b/exe/FeatureExtraction/FeatureExtraction.cpp @@ -415,30 +415,6 @@ int main (int argc, char **argv) // Work out the pose of the head from the tracked model cv::Vec6d pose_estimate = LandmarkDetector::GetPose(face_model, fx, fy, cx, cy); - // TODO move to recorder Write the similarity normalised output - //if (!output_similarity_align.empty()) - //{ - - // char name[100]; - - // // Filename is based on frame number - // std::sprintf(name, "frame_det_%06d.bmp", frame_count + 1); - - // // Construct the output filename - // boost::filesystem::path slash("/"); - - // std::string preferredSlash = slash.make_preferred().string(); - - // string out_file = output_similarity_align[f_n] + preferredSlash + string(name); - // bool write_success = imwrite(out_file, sim_warped_img); - - // if (!write_success) - // { - // cout << "Could not output similarity aligned image image" << endl; - // return 1; - // } - //} - // Visualising the tracker, TODO this should be in utility if (recording_params.outputTrackedVideo() || (visualize_track && !det_parameters.quiet_mode)) { diff --git a/lib/local/Recorder/include/RecorderOpenFace.h b/lib/local/Recorder/include/RecorderOpenFace.h index e5db78b..dfe96c4 100644 --- a/lib/local/Recorder/include/RecorderOpenFace.h +++ b/lib/local/Recorder/include/RecorderOpenFace.h @@ -107,6 +107,7 @@ namespace Recorder std::string record_root; std::string filename; std::string csv_filename; + std::string aligned_output_directory; // The actual output file stream that will be written RecorderCSV csv_recorder; @@ -143,6 +144,9 @@ namespace Recorder std::string video_filename; cv::Mat vis_to_out; + // For aligned face writing + cv::Mat aligned_face; + }; } #endif \ No newline at end of file diff --git a/lib/local/Recorder/src/RecorderOpenFace.cpp b/lib/local/Recorder/src/RecorderOpenFace.cpp index 6c23e09..1b67de9 100644 --- a/lib/local/Recorder/src/RecorderOpenFace.cpp +++ b/lib/local/Recorder/src/RecorderOpenFace.cpp @@ -97,12 +97,26 @@ RecorderOpenFace::RecorderOpenFace(const std::string out_directory, const std::s this->video_filename = (path(record_root) / path(filename).replace_extension(".avi")).string(); } - // TODO aligned Prepare image recording + // Prepare image recording + if (params.outputAlignedFaces()) + { + aligned_output_directory = (path(record_root) / path(filename + "_aligned")).string(); + CreateDirectory(aligned_output_directory); + } + observation_count = 0; } +// TODO move to actual write +void RecorderOpenFace::SetObservationFaceAlign(const cv::Mat& aligned_face) +{ + this->aligned_face = aligned_face; + +} + + void RecorderOpenFace::SetObservationVisualization(const cv::Mat &vis_track) { if (params.outputTrackedVideo()) @@ -171,6 +185,28 @@ void RecorderOpenFace::WriteObservation() this->hog_recorder.Write(); } + // Write aligned faces + if (params.outputAlignedFaces()) + { + char name[100]; + + // Filename is based on frame number + std::sprintf(name, "frame_det_%06d.bmp", observation_count); + + // Construct the output filename + boost::filesystem::path slash("/"); + + std::string preferredSlash = slash.make_preferred().string(); + + string out_file = aligned_output_directory + preferredSlash + string(name); + bool write_success = cv::imwrite(out_file, aligned_face); + + if (!write_success) + { + WARN_STREAM("Could not output similarity aligned image image"); + } + } + if(params.outputTrackedVideo()) { if (vis_to_out.empty())