From 7f3ed9c855401165d6d4de22dbd69980eebf7294 Mon Sep 17 00:00:00 2001 From: Tadas Baltrusaitis Date: Fri, 3 Nov 2017 20:00:24 +0000 Subject: [PATCH] Towards a big recording simplification. --- exe/FeatureExtraction/FeatureExtraction.cpp | 2 ++ lib/local/Recorder/include/RecorderOpenFace.h | 6 +----- .../include/RecorderOpenFaceParameters.h | 7 +++++-- lib/local/Recorder/src/RecorderOpenFace.cpp | 17 +++++++++-------- 4 files changed, 17 insertions(+), 15 deletions(-) diff --git a/exe/FeatureExtraction/FeatureExtraction.cpp b/exe/FeatureExtraction/FeatureExtraction.cpp index 2e6fc1c..a2f8a01 100644 --- a/exe/FeatureExtraction/FeatureExtraction.cpp +++ b/exe/FeatureExtraction/FeatureExtraction.cpp @@ -341,6 +341,8 @@ int main (int argc, char **argv) fy = fx; } + Recorder::RecorderOpenFaceParameters params(arguments); + // TODO this should always be video input int num_eye_landmarks = LandmarkDetector::CalculateAllEyeLandmarks(face_model).size(); // TODO empty file check replaced Recorder::RecorderOpenFace openFaceRec(output_files[f_n], input_files[f_n], true, output_2D_landmarks, output_3D_landmarks, output_model_params, output_pose, output_AUs, output_gaze, !output_hog_align_files.empty(), diff --git a/lib/local/Recorder/include/RecorderOpenFace.h b/lib/local/Recorder/include/RecorderOpenFace.h index 1c4bdc0..5499f6b 100644 --- a/lib/local/Recorder/include/RecorderOpenFace.h +++ b/lib/local/Recorder/include/RecorderOpenFace.h @@ -57,9 +57,7 @@ namespace Recorder public: // The constructor for the recorder, need to specify if we are recording a sequence or not - RecorderOpenFace(const std::string out_directory, const std::string in_filename, Recorder::RecorderOpenFaceParameter params, - // TODO here int num_face_landmarks, int num_model_modes, int num_eye_landmarks, - const std::vector& au_names_class, const std::vector& au_names_reg, const std::string& output_codec, double fps_vid_in); + RecorderOpenFace(const std::string out_directory, const std::string in_filename, RecorderOpenFaceParameters parameters); // Simplified constructor that records all, TODO implement RecorderOpenFace(const std::string out_directory, const std::string in_filename, bool sequence, int num_face_landmarks, int num_model_modes, int num_eye_landmarks, @@ -143,8 +141,6 @@ namespace Recorder // For video writing cv::VideoWriter video_writer; std::string video_filename; - std::string output_codec; - double fps_vid_out; cv::Mat vis_to_out; }; diff --git a/lib/local/Recorder/include/RecorderOpenFaceParameters.h b/lib/local/Recorder/include/RecorderOpenFaceParameters.h index ea59500..2c85faf 100644 --- a/lib/local/Recorder/include/RecorderOpenFaceParameters.h +++ b/lib/local/Recorder/include/RecorderOpenFaceParameters.h @@ -52,7 +52,7 @@ namespace Recorder public: // Constructors RecorderOpenFaceParameters(); - RecorderOpenFaceParameters(vector &arguments); + RecorderOpenFaceParameters(vector &arguments, double fps_vid_out = 30, std::string output_codec = "DIVX"); @@ -85,7 +85,10 @@ namespace Recorder bool output_hog; bool output_tracked_video; bool output_aligned_faces; - + + // Some video recording parameters + std::string output_codec; + double fps_vid_out; }; } diff --git a/lib/local/Recorder/src/RecorderOpenFace.cpp b/lib/local/Recorder/src/RecorderOpenFace.cpp index 956515e..a025c01 100644 --- a/lib/local/Recorder/src/RecorderOpenFace.cpp +++ b/lib/local/Recorder/src/RecorderOpenFace.cpp @@ -71,12 +71,7 @@ void CreateDirectory(std::string output_path) } -RecorderOpenFace::RecorderOpenFace(const std::string out_directory, const std::string in_filename, bool sequence, bool output_2D_landmarks, bool output_3D_landmarks, bool output_model_params, bool output_pose, - bool output_AUs, bool output_gaze, bool output_hog, bool output_tracked_video, bool output_aligned_faces, int num_face_landmarks, int num_model_modes, int num_eye_landmarks, - const std::vector& au_names_class, const std::vector& au_names_reg, const std::string& output_codec, double fps_vid_in): - is_sequence(sequence), output_2D_landmarks(output_2D_landmarks), output_3D_landmarks(output_3D_landmarks), output_aligned_faces(output_aligned_faces), - output_AUs(output_AUs), output_gaze(output_gaze), output_hog(output_hog), output_model_params(output_model_params), - output_pose(output_pose), output_tracked_video(output_tracked_video), video_writer(), fps_vid_out(fps_vid_in), output_codec(output_codec) +RecorderOpenFace::RecorderOpenFace(const std::string out_directory, const std::string in_filename, RecorderOpenFaceParameters parameters):video_writer(), params(parameters) { // From the filename, strip out the name without directory and extension @@ -88,8 +83,7 @@ RecorderOpenFace::RecorderOpenFace(const std::string out_directory, const std::s // Create the required individual recorders, CSV, HOG, aligned, video std::string csv_filename = (path(record_root) / path(filename).replace_extension(".csv")).string(); - csv_recorder.Open(csv_filename, output_2D_landmarks, output_3D_landmarks, output_model_params, output_pose, - output_AUs, output_gaze, num_face_landmarks, num_model_modes, num_eye_landmarks, au_names_class, au_names_reg); + // Consruct HOG recorder here if(output_hog) @@ -143,6 +137,13 @@ void RecorderOpenFace::WriteObservation() observation_count++; // Write out the CSV file (it will always be there, even if not outputting anything more but frame/face numbers) + + if(observation_count == 1) + { + csv_recorder.Open(csv_filename, output_2D_landmarks, output_3D_landmarks, output_model_params, output_pose, + output_AUs, output_gaze, num_face_landmarks, num_model_modes, num_eye_landmarks, au_names_class, au_names_reg); + } + this->csv_recorder.WriteLine(observation_count, timestamp, landmark_detection_success, landmark_detection_confidence, landmarks_2D, landmarks_3D, pdm_params_local, pdm_params_global, head_pose, gaze_direction0, gaze_direction1, gaze_angle, eye_landmarks, au_intensities, au_occurences);