Video writing bug fix, work on demo scripts for feature extraction.

This commit is contained in:
Tadas Baltrusaitis 2017-11-23 09:07:12 +00:00
parent a70fe65356
commit d6dd2f9a45
4 changed files with 46 additions and 52 deletions

View file

@ -189,7 +189,7 @@ void RecorderOpenFace::SetObservationVisualization(const cv::Mat &vis_track)
if (params.outputTracked()) if (params.outputTracked())
{ {
// Initialize the video writer if it has not been opened yet // Initialize the video writer if it has not been opened yet
if(video_writer.isOpened()) if(params.isSequence())
{ {
std::string output_codec = params.outputCodec(); std::string output_codec = params.outputCodec();
try try

View file

@ -1,50 +1,24 @@
% A demo script that demonstrates how to process a single video file using
% OpenFace and extract and visualize all of the features
clear clear
% The location executable will depend on the OS
if(isunix) if(isunix)
executable = '"../../build/bin/FeatureExtraction"'; executable = '"../../build/bin/FeatureExtraction"';
else else
executable = '"../../x64/Release/FeatureExtraction.exe"'; executable = '"../../x64/Release/FeatureExtraction.exe"';
end end
output = './output_features_vid/'; % Input file
in_file = '../../samples/default.wmv';
if(~exist(output, 'file')) % Where to store the output
mkdir(output) output_dir = './processed_features/';
end
in_files = dir('../../samples/default.wmv'); % This will take file after -f and output all the features to directory
% some parameters % after -out_dir
verbose = true; command = sprintf('%s -f "%s" -out_dir "%s" -verbose', executable, in_file, output_dir);
command = executable;
% Remove for a speedup
command = cat(2, command, ' -verbose ');
% add all videos to single argument list (so as not to load the model anew
% for every video)
for i=1:numel(in_files)
inputFile = ['../../samples/', in_files(i).name];
[~, name, ~] = fileparts(inputFile);
% where to output tracking results
outputFile = [output name '.txt'];
if(~exist([output name], 'file'))
mkdir([output name]);
end
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, [' -simalign "' outputDir_aligned '" -hogalign "' outputHOG_aligned '"' ]);
end
if(isunix) if(isunix)
unix(command); unix(command);
@ -54,15 +28,30 @@ end
%% Demonstrating reading the output files %% Demonstrating reading the output files
% First read in the column names % Most of the features will be in the csv file in the output directory with
tab = readtable(outputFile); % the same name as the input file
[~,name,~] = fileparts(in_file);
output_csv = sprintf('%s/%s.csv', output_dir, name);
% First read in the column names, to know which columns to read for
% particular features
tab = readtable(output_csv);
column_names = tab.Properties.VariableNames; column_names = tab.Properties.VariableNames;
all_params = dlmread(outputFile, ',', 1, 0); % Read all of the data
all_params = dlmread(output_csv, ',', 1, 0);
% This indicates which frames were succesfully tracked % This indicates which frames were succesfully tracked
valid_frames = logical(all_params(:,4));
time = all_params(valid_frames, 2); % Find which column contains success of tracking data and timestamp data
valid_ind = cellfun(@(x) ~isempty(x) && x==1, strfind(column_names, 'success'));
time_stamp_ind = cellfun(@(x) ~isempty(x) && x==1, strfind(column_names, 'timestamp'));
% Extract tracking success data and only read those frame
valid_frames = logical(all_params(:,valid_ind));
% Get the timestamp data
time_stamps = all_params(valid_frames, time_stamp_ind);
%% Finding which header line starts with p_ (basically model params) %% Finding which header line starts with p_ (basically model params)
shape_inds = cellfun(@(x) ~isempty(x) && x==1, strfind(column_names, 'p_')); shape_inds = cellfun(@(x) ~isempty(x) && x==1, strfind(column_names, 'p_'));
@ -71,7 +60,7 @@ shape_inds = cellfun(@(x) ~isempty(x) && x==1, strfind(column_names, 'p_'));
shape_params = all_params(valid_frames, shape_inds); shape_params = all_params(valid_frames, shape_inds);
figure figure
plot(time, shape_params); plot(time_stamps, shape_params);
title('Shape parameters'); title('Shape parameters');
xlabel('Time (s)'); xlabel('Time (s)');
@ -113,9 +102,20 @@ xs = all_params(valid_frames, landmark_inds_x);
ys = all_params(valid_frames, landmark_inds_y); ys = all_params(valid_frames, landmark_inds_y);
zs = all_params(valid_frames, landmark_inds_z); zs = all_params(valid_frames, landmark_inds_z);
eye_landmark_inds_x = cellfun(@(x) ~isempty(x) && x==1, strfind(column_names, 'eye_lmk_X_'));
eye_landmark_inds_y = cellfun(@(x) ~isempty(x) && x==1, strfind(column_names, 'eye_lmk_Y_'));
eye_landmark_inds_z = cellfun(@(x) ~isempty(x) && x==1, strfind(column_names, 'eye_lmk_Z_'));
eye_xs = all_params(valid_frames, eye_landmark_inds_x);
eye_ys = all_params(valid_frames, eye_landmark_inds_y);
eye_zs = all_params(valid_frames, eye_landmark_inds_z);
figure figure
for j = 1:size(xs,1) for j = 1:size(xs,1)
plot3(xs(j,:), ys(j,:), zs(j,:), '.');axis equal; plot3(xs(j,:), ys(j,:), zs(j,:), '.');axis equal;
hold on;
plot3(eye_xs(j,:), eye_ys(j,:), eye_zs(j,:), '.r');
hold off;
xlabel('X (mm)'); xlabel('X (mm)');
ylabel('Y (mm)'); ylabel('Y (mm)');
zlabel('Z (mm)'); zlabel('Z (mm)');

View file

@ -8,12 +8,6 @@ else
executable = '"../../x64/Release/FaceLandmarkVidMulti.exe"'; executable = '"../../x64/Release/FaceLandmarkVidMulti.exe"';
end end
output = './demo_vid/';
if(~exist(output, 'file'))
mkdir(output)
end
in_files = dir('../../samples/multi_face.avi'); in_files = dir('../../samples/multi_face.avi');
model = 'model/main_clnf_general.txt'; % Trained on in the wild and multi-pie data (a CLNF model) model = 'model/main_clnf_general.txt'; % Trained on in the wild and multi-pie data (a CLNF model)

View file

@ -22,8 +22,8 @@ model = 'model/main_clnf_general.txt'; % Trained on in the wild and multi-pie da
% Create a command that will run the tracker on set of videos and display the output % Create a command that will run the tracker on set of videos and display the output
command = sprintf('%s -mloc "%s" ', executable, model); command = sprintf('%s -mloc "%s" ', executable, model);
% add all videos to single argument list (so as not to load the model anew % add all videos to single argument list by appending -f comments
% for every video) % so as not to load the model anew for every video)
for i=1:numel(in_files) for i=1:numel(in_files)
inputFile = ['../../samples/', in_files(i).name]; inputFile = ['../../samples/', in_files(i).name];
command = cat(2, command, [' -f "' inputFile '" ']); command = cat(2, command, [' -f "' inputFile '" ']);