Unifying input and output of GUI and command line versions.

This commit is contained in:
Tadas Baltrusaitis 2016-12-09 15:07:31 -05:00
parent 29d13878da
commit 41fc0bd43c
6 changed files with 87 additions and 98 deletions

View file

@ -613,8 +613,8 @@ int main (int argc, char **argv)
char name[100]; char name[100];
// output the frame number // Filename is based on frame number
std::sprintf(name, "frame_det_%06d.bmp", frame_count); std::sprintf(name, "frame_det_%06d.bmp", frame_count + 1);
// Construct the output filename // Construct the output filename
boost::filesystem::path slash("/"); boost::filesystem::path slash("/");

View file

@ -48,7 +48,18 @@ namespace OpenFaceOffline
if (output_gaze) 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) 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, 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)); gaze.Item2.Item1, gaze.Item2.Item2, gaze.Item2.Item3, gaze_angle.Item1, gaze_angle.Item2));
List<Tuple<double, double>> 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) if (output_pose)

View file

@ -214,7 +214,7 @@ public:
char name[100]; char name[100];
// output the frame number // 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(); string out_file = (boost::filesystem::path(*align_output_dir) / boost::filesystem::path(name)).string();
imwrite(out_file, *aligned_face); imwrite(out_file, *aligned_face);

View file

@ -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

View file

@ -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

View file

@ -25,7 +25,7 @@ for i=1:numel(in_files)
[~, name, ~] = fileparts(inputFile); [~, name, ~] = fileparts(inputFile);
% where to output tracking results % where to output tracking results
outputFile = [output name '.txt']; outputFile = [output name '.csv'];
if(~exist([output name], 'file')) if(~exist([output name], 'file'))
mkdir([output name]); mkdir([output name]);
@ -35,10 +35,8 @@ for i=1:numel(in_files)
outputHOG_aligned = [output name '.hog']; outputHOG_aligned = [output name '.hog'];
output_shape_params = [output name '.params.txt'];
command = cat(2, command, [' -f "' inputFile '" -of "' outputFile '"']); 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 end
@ -161,7 +159,7 @@ legend('show');
hold off; hold off;
%% Output HOG files %% 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 %% Output aligned images
img_files = dir([outputDir_aligned, '/*.bmp']); img_files = dir([outputDir_aligned, '/*.bmp']);