
%%%%%%%%%%%%%%  Run detector on a directory of images  %%%%%%%%%%%
%
% Designate an image directory by uncommenting one of the following, 
% or by choosing an image directory of your own. 

imgdir = 'testImages1';  %Contains AU 1,2,12,14 from NSF Subject 16. 
%imgdir = 'testImages2'; %Contains AU 1,4,10,14 from NSF Subject 16.
%imgdir = 'testImages3'; %Contains AU 1,2,4,10,14 from NSF Subject 30.
%imgdir = 'testImages4'; %Contains AU 2,4,5,10,20 from NSF Subject 86  
%imgdir = 'testImages5'; %Contains AU 1,2,10 from NSF subject 80
  %imgdir = 'jen_face3';
  %imgdir = '/RAID4/NRL/D005-TestSubjects/S264_inter';
  %imgdir = '/RAID4/NRL/D005-TestSubjects/S325_inter';
  %imgdir = '/RAID4/NRL/D005-TestSubjects/S327_inter';
  %imgdir = '/RAID4/NRL/D005-TestSubjects/S331_inter';

%These are some extras
%imgdir = 'testImages8'; %Contains AU 1,2,14 from NSF Subject 16.
%imgdir = 'testImages9';  %Contains AU 12,14 from NSF Subject 86 

% The following command runs CERT. CERT reads each image from the 
% directory imgdir, automatically detects the face and eye postions, 
% then passes it through a set of 8 AU detectors. The results are 
% written to the matrix AUout. Type 'help CERT' for more info. 

[EyePosn,AUout,imNames,facefound]=CERT(imgdir);

% The Matlab version runs out of memory at about 3500 frames. If that happens, 
% quit and restart matlab, then use the following to restart CERT:  

load temp_out;
[EyePosn,AUout,imNames,facefound]=CERT_restart(imgdir,i,EyePosn,Yout,r,facefound);


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   

%%%%%%%%%%%%%%% Organize and write result files  %%%%%%%%%%%%%%%
% 
% The following function saves the relevant matlab variables, 
% and also writes an output matrix in tab-delimited 
% text with column labels.  It creates a matrix called Results, 
% in which each line contains the frame number and the raw output 
% of each of the 8 AU detectors, for all frames for which a face 
% was found. The results are written to the parent directory of imgdir, 
% with filenames [imgdir]'out.mat' and [imgdir]'out.txt'.

Results=write_resultfiles(imgdir,EyePosn,AUout,imNames,facefound);

% Note that the function reads the frame number off the image filename. 
% It assumes the last 4 characters before the extension are the 
% frame number. Hence when you want to run images that are named a 
% different way, you'll need to tweak that line.

%%%%%%%%%%%%%%% Make output demo %%%%%%%%%%%%%%% 

M = make_demo(EyePosn,AUout,imgdir,imNames);

%Run this one for image directories greater than 3000 frames
M = make_demo(EyePosn,AUout,imgdir,imNames,1000,2000);

% This demo creates an AVI file showing the face with 
% the detected eye positions and the AU output. 
% The avi file is written to the directory above imgdir, with 
% filename [imgdir]'out.avi'.  Make sure nothing is occluding 
% the figure window since it will show up in your avi.  Wait a couple of 
% seconds after it finishes, since the movie will replay twice in matlab.  
% The bar graphs show the raw output of each AU detector for each frame. 
% 100 frames at a time are shown.  When there are more than 100 frames 
% it will display a sliding window of 100. There is no upper limit to 
% the number of frames, but the avi file will get rather large. 

% View a matlab version of the movie:
clf reset
tmp = frame2im(M(1));imshow(tmp); %Expands the window
movie(M,2)                        %Play movie twice




  
  

  
  
