From 67041371dd215d64370b5c13f2cae11461e2a2ee Mon Sep 17 00:00:00 2001 From: Tadas Baltrusaitis Date: Tue, 12 Dec 2017 17:48:46 +0000 Subject: [PATCH] Correct metafile output for webcam. --- exe/FaceLandmarkImg/FaceLandmarkImg.cpp | 2 +- exe/FeatureExtraction/FeatureExtraction.cpp | 2 +- .../Utilities/include/RecorderOpenFaceParameters.h | 5 ++++- lib/local/Utilities/src/RecorderOpenFace.cpp | 11 ++++++----- .../Utilities/src/RecorderOpenFaceParameters.cpp | 4 ++-- 5 files changed, 14 insertions(+), 10 deletions(-) diff --git a/exe/FaceLandmarkImg/FaceLandmarkImg.cpp b/exe/FaceLandmarkImg/FaceLandmarkImg.cpp index 71c0ab2..0c97339 100644 --- a/exe/FaceLandmarkImg/FaceLandmarkImg.cpp +++ b/exe/FaceLandmarkImg/FaceLandmarkImg.cpp @@ -186,7 +186,7 @@ int main (int argc, char **argv) while (!captured_image.empty()) { - Utilities::RecorderOpenFaceParameters recording_params(arguments, false, + Utilities::RecorderOpenFaceParameters recording_params(arguments, false, false, image_reader.fx, image_reader.fy, image_reader.cx, image_reader.cy); Utilities::RecorderOpenFace open_face_rec(image_reader.name, recording_params, arguments); diff --git a/exe/FeatureExtraction/FeatureExtraction.cpp b/exe/FeatureExtraction/FeatureExtraction.cpp index dad67d8..adc424f 100644 --- a/exe/FeatureExtraction/FeatureExtraction.cpp +++ b/exe/FeatureExtraction/FeatureExtraction.cpp @@ -140,7 +140,7 @@ int main (int argc, char **argv) cv::Mat captured_image; - Utilities::RecorderOpenFaceParameters recording_params(arguments, true, + Utilities::RecorderOpenFaceParameters recording_params(arguments, true, sequence_reader.IsWebcam(), sequence_reader.fx, sequence_reader.fy, sequence_reader.cx, sequence_reader.cy, sequence_reader.fps); Utilities::RecorderOpenFace open_face_rec(sequence_reader.name, recording_params, arguments); diff --git a/lib/local/Utilities/include/RecorderOpenFaceParameters.h b/lib/local/Utilities/include/RecorderOpenFaceParameters.h index 1dbb462..d2cbf16 100644 --- a/lib/local/Utilities/include/RecorderOpenFaceParameters.h +++ b/lib/local/Utilities/include/RecorderOpenFaceParameters.h @@ -53,9 +53,10 @@ namespace Utilities public: // Constructors - RecorderOpenFaceParameters(std::vector &arguments, bool sequence, float fx = -1, float fy = -1, float cx = -1, float cy = -1, double fps_vid_out = 30); + RecorderOpenFaceParameters(std::vector &arguments, bool sequence, bool is_from_webcam, float fx = -1, float fy = -1, float cx = -1, float cy = -1, double fps_vid_out = 30); bool isSequence() const { return is_sequence; } + bool isFromWebcam() const { return is_from_webcam; } bool output2DLandmarks() const { return output_2D_landmarks; } bool output3DLandmarks() const { return output_3D_landmarks; } bool outputPDMParams() const { return output_model_params; } @@ -77,6 +78,8 @@ namespace Utilities // If we are recording results from a sequence each row refers to a frame, if we are recording an image each row is a face bool is_sequence; + // If the data is coming from a webcam + bool is_from_webcam; // Keep track of what we are recording bool output_2D_landmarks; diff --git a/lib/local/Utilities/src/RecorderOpenFace.cpp b/lib/local/Utilities/src/RecorderOpenFace.cpp index 7bb2adb..3483bab 100644 --- a/lib/local/Utilities/src/RecorderOpenFace.cpp +++ b/lib/local/Utilities/src/RecorderOpenFace.cpp @@ -144,7 +144,7 @@ RecorderOpenFace::RecorderOpenFace(const std::string in_filename, RecorderOpenFa } // Populate relative and full path names in the meta file, unless it is a webcam - if(in_filename.compare("webcam") != 0) + if(!params.isFromWebcam()) { string input_filename_relative = in_filename; string input_filename_full = in_filename; @@ -158,7 +158,7 @@ RecorderOpenFace::RecorderOpenFace(const std::string in_filename, RecorderOpenFa else { // Populate the metadata file - metadata_file << "Input:" << in_filename << endl; + metadata_file << "Input:webcam" << endl; } metadata_file << "Camera parameters:" << parameters.getFx() << "," << parameters.getFy() << "," << parameters.getCx() << "," << parameters.getCy() << endl; @@ -271,9 +271,6 @@ void RecorderOpenFace::WriteObservation() std::sort(au_names_reg.begin(), au_names_reg.end()); - csv_recorder.Open(csv_filename, params.isSequence(), params.output2DLandmarks(), params.output3DLandmarks(), params.outputPDMParams(), params.outputPose(), - params.outputAUs(), params.outputGaze(), num_face_landmarks, num_model_modes, num_eye_landmarks, au_names_class, au_names_reg); - metadata_file << "Output csv:" << csv_filename << endl; metadata_file << "Gaze: " << params.outputGaze() << endl; metadata_file << "AUs: " << params.outputAUs() << endl; @@ -281,6 +278,10 @@ void RecorderOpenFace::WriteObservation() metadata_file << "Landmarks 3D: " << params.output3DLandmarks() << endl; metadata_file << "Pose: " << params.outputPose() << endl; metadata_file << "Shape parameters: " << params.outputPDMParams() << endl; + + csv_filename = (path(record_root) / csv_filename).string(); + csv_recorder.Open(csv_filename, params.isSequence(), params.output2DLandmarks(), params.output3DLandmarks(), params.outputPDMParams(), params.outputPose(), + params.outputAUs(), params.outputGaze(), 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, diff --git a/lib/local/Utilities/src/RecorderOpenFaceParameters.cpp b/lib/local/Utilities/src/RecorderOpenFaceParameters.cpp index 15fff7f..20b58df 100644 --- a/lib/local/Utilities/src/RecorderOpenFaceParameters.cpp +++ b/lib/local/Utilities/src/RecorderOpenFaceParameters.cpp @@ -37,13 +37,13 @@ using namespace std; using namespace Utilities; -RecorderOpenFaceParameters::RecorderOpenFaceParameters(std::vector &arguments, bool sequence, float fx, float fy, float cx, float cy, double fps_vid_out) +RecorderOpenFaceParameters::RecorderOpenFaceParameters(std::vector &arguments, bool sequence, bool from_webcam, float fx, float fy, float cx, float cy, double fps_vid_out) { string separator = string(1, boost::filesystem::path::preferred_separator); this->is_sequence = sequence; - + this->is_from_webcam = from_webcam; this->fx = fx; this->fy = fy; this->cx = cx;