From 41fc0bd43cde295b2a9d62baf3de1efbd8343868 Mon Sep 17 00:00:00 2001 From: Tadas Baltrusaitis Date: Fri, 9 Dec 2016 15:07:31 -0500 Subject: [PATCH] Unifying input and output of GUI and command line versions. --- exe/FeatureExtraction/FeatureExtraction.cpp | 4 +- gui/OpenFaceOffline/Recorder.cs | 22 ++++- lib/local/CppInerop/FaceAnalyserInterop.h | 2 +- matlab_runners/Demos/Read_HOG_file.m | 59 +++++++++++++ matlab_runners/Demos/Read_HOG_files.m | 88 ------------------- .../Demos/feature_extraction_demo_vid.m | 10 +-- 6 files changed, 87 insertions(+), 98 deletions(-) create mode 100644 matlab_runners/Demos/Read_HOG_file.m delete mode 100644 matlab_runners/Demos/Read_HOG_files.m diff --git a/exe/FeatureExtraction/FeatureExtraction.cpp b/exe/FeatureExtraction/FeatureExtraction.cpp index b138acb..98c168d 100644 --- a/exe/FeatureExtraction/FeatureExtraction.cpp +++ b/exe/FeatureExtraction/FeatureExtraction.cpp @@ -613,8 +613,8 @@ int main (int argc, char **argv) char name[100]; - // output the frame number - std::sprintf(name, "frame_det_%06d.bmp", frame_count); + // Filename is based on frame number + std::sprintf(name, "frame_det_%06d.bmp", frame_count + 1); // Construct the output filename boost::filesystem::path slash("/"); diff --git a/gui/OpenFaceOffline/Recorder.cs b/gui/OpenFaceOffline/Recorder.cs index adfa713..ce77fb9 100644 --- a/gui/OpenFaceOffline/Recorder.cs +++ b/gui/OpenFaceOffline/Recorder.cs @@ -48,7 +48,18 @@ namespace OpenFaceOffline if (output_gaze) { - output_features_file.Write(", gaze_0_x, gaze_0_y, gaze_0_z, gaze_1_x, gaze_1_y, gaze_1_z"); + output_features_file.Write(", gaze_0_x, gaze_0_y, gaze_0_z, gaze_1_x, gaze_1_y, gaze_1_z, gaze_angle_x, gaze_angle_y"); + + // Output gaze eye landmarks + int gaze_num_lmks = clnf_model.CalculateEyeLandmarks().Count; + for (int i = 0; i < gaze_num_lmks; ++i) + { + output_features_file.Write(", eye_lmk_x_" + i); + } + for (int i = 0; i < gaze_num_lmks; ++i) + { + output_features_file.Write(", eye_lmk_y_" + i); + } } if (output_pose) @@ -149,6 +160,15 @@ namespace OpenFaceOffline output_features_file.Write(String.Format(", {0:F5}, {1:F5}, {2:F5}, {3:F5}, {4:F5}, {5:F5}, {6:F5}, {7:F5}", gaze.Item1.Item1, gaze.Item1.Item2, gaze.Item1.Item3, gaze.Item2.Item1, gaze.Item2.Item2, gaze.Item2.Item3, gaze_angle.Item1, gaze_angle.Item2)); + + List> landmarks_2d = clnf_model.CalculateEyeLandmarks(); + + for (int i = 0; i < landmarks_2d.Count; ++i) + output_features_file.Write(", {0:F2}", landmarks_2d[i].Item1); + + for (int i = 0; i < landmarks_2d.Count; ++i) + output_features_file.Write(", {0:F2}", landmarks_2d[i].Item2); + } if (output_pose) diff --git a/lib/local/CppInerop/FaceAnalyserInterop.h b/lib/local/CppInerop/FaceAnalyserInterop.h index 624a1fc..a8eac76 100644 --- a/lib/local/CppInerop/FaceAnalyserInterop.h +++ b/lib/local/CppInerop/FaceAnalyserInterop.h @@ -214,7 +214,7 @@ public: char name[100]; // output the frame number - sprintf(name, "frame_det_%06d.png", frame_num); + sprintf(name, "frame_det_%06d.bmp", frame_num); string out_file = (boost::filesystem::path(*align_output_dir) / boost::filesystem::path(name)).string(); imwrite(out_file, *aligned_face); diff --git a/matlab_runners/Demos/Read_HOG_file.m b/matlab_runners/Demos/Read_HOG_file.m new file mode 100644 index 0000000..d92bc68 --- /dev/null +++ b/matlab_runners/Demos/Read_HOG_file.m @@ -0,0 +1,59 @@ +function [hog_data, valid_inds] = Read_HOG_file(hog_file) + + valid_inds = []; + + f = fopen(hog_file, 'r'); + + curr_data = []; + curr_ind = 0; + + while(~feof(f)) + + if(curr_ind == 0) + num_cols = fread(f, 1, 'int32'); + if(isempty(num_cols)) + break; + end + + num_rows = fread(f, 1, 'int32'); + num_chan = fread(f, 1, 'int32'); + + curr_ind = curr_ind + 1; + + % preallocate some space + if(curr_ind == 1) + curr_data = zeros(1000, 1 + num_rows * num_cols * num_chan); + num_feats = 1 + num_rows * num_cols * num_chan; + end + + if(curr_ind > size(curr_data,1)) + curr_data = cat(1, curr_data, zeros(1000, 1 + num_rows * num_cols * num_chan)); + end + feature_vec = fread(f, [1, 1 + num_rows * num_cols * num_chan], 'float32'); + curr_data(curr_ind, :) = feature_vec; + else + + % Reading in batches of 5000 + + feature_vec = fread(f, [4 + num_rows * num_cols * num_chan, 5000], 'float32'); + feature_vec = feature_vec(4:end,:)'; + + num_rows_read = size(feature_vec,1); + + if(~isempty(feature_vec)) + curr_data(curr_ind+1:curr_ind+num_rows_read,:) = feature_vec; + curr_ind = curr_ind + size(feature_vec,1); + end + end + + end + + fclose(f); + + hog_data = curr_data(1:curr_ind,:); + + if(~isempty(hog_data)) + valid_inds = hog_data(:,1); + hog_data = hog_data(:,2:end); + end +end \ No newline at end of file diff --git a/matlab_runners/Demos/Read_HOG_files.m b/matlab_runners/Demos/Read_HOG_files.m deleted file mode 100644 index b3dbd71..0000000 --- a/matlab_runners/Demos/Read_HOG_files.m +++ /dev/null @@ -1,88 +0,0 @@ -function [hog_data, valid_inds, vid_id] = Read_HOG_files(users, hog_data_dir) - - hog_data = []; - vid_id = {}; - valid_inds = []; - - feats_filled = 0; - - for i=1:numel(users) - - hog_files = dir([hog_data_dir, users{i} '*.hog']); - - for h=1:numel(hog_files) - hog_file = [hog_data_dir, hog_files(h).name]; - f = fopen(hog_file, 'r'); - - curr_data = []; - curr_ind = 0; - - while(~feof(f)) - - if(curr_ind == 0) - num_cols = fread(f, 1, 'int32'); - if(isempty(num_cols)) - break; - end - - num_rows = fread(f, 1, 'int32'); - num_chan = fread(f, 1, 'int32'); - - curr_ind = curr_ind + 1; - - % preallocate some space - if(curr_ind == 1) - curr_data = zeros(1000, 1 + num_rows * num_cols * num_chan); - num_feats = 1 + num_rows * num_cols * num_chan; - end - - if(curr_ind > size(curr_data,1)) - curr_data = cat(1, curr_data, zeros(1000, 1 + num_rows * num_cols * num_chan)); - end - feature_vec = fread(f, [1, 1 + num_rows * num_cols * num_chan], 'float32'); - curr_data(curr_ind, :) = feature_vec; - else - - % Reading in batches of 5000 - - feature_vec = fread(f, [4 + num_rows * num_cols * num_chan, 5000], 'float32'); - feature_vec = feature_vec(4:end,:)'; - - num_rows_read = size(feature_vec,1); - - if(~isempty(feature_vec)) - curr_data(curr_ind+1:curr_ind+num_rows_read,:) = feature_vec; - curr_ind = curr_ind + size(feature_vec,1); - end - end - - end - - fclose(f); - - curr_data = curr_data(1:curr_ind,:); - vid_id_curr = cell(curr_ind,1); - vid_id_curr(:) = users(i); - - vid_id = cat(1, vid_id, vid_id_curr); - - % Assume same number of frames per video - if(i==1 && h == 1) - hog_data = zeros(curr_ind * numel(users) * 8, num_feats); - end - - if(size(hog_data,1) < feats_filled+curr_ind) - hog_data = cat(1, hog_data, zeros(size(hog_data,1), num_feats)); - end - - hog_data(feats_filled+1:feats_filled+curr_ind,:) = curr_data; - - feats_filled = feats_filled + curr_ind; - end - end - - if(~isempty(hog_data)) - valid_inds = hog_data(1:feats_filled,1); - hog_data = hog_data(1:feats_filled,2:end); - end -end \ No newline at end of file diff --git a/matlab_runners/Demos/feature_extraction_demo_vid.m b/matlab_runners/Demos/feature_extraction_demo_vid.m index 0575b79..0087dc0 100644 --- a/matlab_runners/Demos/feature_extraction_demo_vid.m +++ b/matlab_runners/Demos/feature_extraction_demo_vid.m @@ -25,7 +25,7 @@ for i=1:numel(in_files) [~, name, ~] = fileparts(inputFile); % where to output tracking results - outputFile = [output name '.txt']; + outputFile = [output name '.csv']; if(~exist([output name], 'file')) mkdir([output name]); @@ -34,11 +34,9 @@ for i=1:numel(in_files) outputDir_aligned = [output name]; outputHOG_aligned = [output name '.hog']; - - output_shape_params = [output name '.params.txt']; - + command = cat(2, command, [' -f "' inputFile '" -of "' outputFile '"']); - command = cat(2, command, [' -simsize 224 -simalign "' outputDir_aligned '" -hogalign "' outputHOG_aligned '"' ]); + command = cat(2, command, [' -au_static -simsize 224 -simalign "' outputDir_aligned '" -hogalign "' outputHOG_aligned '"' ]); end @@ -161,7 +159,7 @@ legend('show'); hold off; %% Output HOG files -[hog_data, valid_inds, vid_id] = Read_HOG_files({name}, output); +[hog_data, valid_inds] = Read_HOG_file(outputHOG_aligned); %% Output aligned images img_files = dir([outputDir_aligned, '/*.bmp']);