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())
{
// Initialize the video writer if it has not been opened yet
if(video_writer.isOpened())
if(params.isSequence())
{
std::string output_codec = params.outputCodec();
try

View File

@ -1,51 +1,25 @@
% A demo script that demonstrates how to process a single video file using
% OpenFace and extract and visualize all of the features
clear
% The location executable will depend on the OS
if(isunix)
executable = '"../../build/bin/FeatureExtraction"';
else
executable = '"../../x64/Release/FeatureExtraction.exe"';
end
output = './output_features_vid/';
% Input file
in_file = '../../samples/default.wmv';
if(~exist(output, 'file'))
mkdir(output)
end
in_files = dir('../../samples/default.wmv');
% some parameters
verbose = true;
% Where to store the output
output_dir = './processed_features/';
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 '"' ]);
% This will take file after -f and output all the features to directory
% after -out_dir
command = sprintf('%s -f "%s" -out_dir "%s" -verbose', executable, in_file, output_dir);
end
if(isunix)
unix(command);
else
@ -54,15 +28,30 @@ end
%% Demonstrating reading the output files
% First read in the column names
tab = readtable(outputFile);
% Most of the features will be in the csv file in the output directory with
% 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;
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
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)
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);
figure
plot(time, shape_params);
plot(time_stamps, shape_params);
title('Shape parameters');
xlabel('Time (s)');
@ -113,9 +102,20 @@ xs = all_params(valid_frames, landmark_inds_x);
ys = all_params(valid_frames, landmark_inds_y);
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
for j = 1:size(xs,1)
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)');
ylabel('Y (mm)');
zlabel('Z (mm)');

View File

@ -7,12 +7,6 @@ if(isunix)
else
executable = '"../../x64/Release/FaceLandmarkVidMulti.exe"';
end
output = './demo_vid/';
if(~exist(output, 'file'))
mkdir(output)
end
in_files = dir('../../samples/multi_face.avi');

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
command = sprintf('%s -mloc "%s" ', executable, model);
% add all videos to single argument list (so as not to load the model anew
% for every video)
% add all videos to single argument list by appending -f comments
% so as not to load the model anew for every video)
for i=1:numel(in_files)
inputFile = ['../../samples/', in_files(i).name];
command = cat(2, command, [' -f "' inputFile '" ']);