-
Notifications
You must be signed in to change notification settings - Fork 378
/
process_video.m
56 lines (51 loc) · 2.19 KB
/
process_video.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
%% double process_video(int, int, string, string);
% method_id - string
% algorithm_id - string
% inFile - string
% outFile - string
%
% demos:
% process_video('RPCA', 'FPCP', 'dataset/demo.avi', 'output/demo_out.avi');
% process_video('RPCA', 'FPCP', 'dataset/demo.avi', 'output/demo_out.mat');
% process_video('RPCA', 'FPCP', 'dataset/demo.mat', 'output/demo_out.mat');
% process_video('RPCA', 'FPCP', 'dataset/demo.mat', 'output/demo_out.avi');
%
% unix:
% ./matlab -nojvm -nodisplay -nosplash -r "process_video('RPCA', 'FPCP', 'dataset/demo.avi', 'output/demo_out.avi');exit;"
% ./matlab -nojvm -nodisplay -nosplash -r "process_video('RPCA', 'FPCP', 'dataset/demo.mat', 'output/demo_out.avi');exit;"
%
% For debug:
% load('output/demo_out.mat');
% showResultsInfo(info);
%
% method_id='RPCA'; algorithm_id='FPCP'; inFile='dataset/demo.avi'; outFile='output/demo_out.avi';
% inFile = 'dataset/ChangeDetection2012/badminton_out.avi';
function [stats] = process_video(method_id, algorithm_id, inFile, outFile)
timerVal = tic;
displog(['Loading ' inFile]);
video = load_video_file(inFile);
%%% Matrix-based methods
% i.e: process_video('RPCA', 'FPCP', 'dataset/demo.avi', 'output/demo_FPCP.avi');
if(strcmp(method_id,'RPCA') || strcmp(method_id,'ST') || strcmp(method_id,'MC') ...
|| strcmp(method_id,'LRR') || strcmp(method_id,'TTD') || strcmp(method_id,'NMF'))
M = im2double(convert_video_to_2d(video));
params.rows = video.height;
params.cols = video.width;
results = run_algorithm(method_id, algorithm_id, M, params);
movobj = convert_2dresults2mov([],results.L,results.S,results.O,video);
end
%%% Tensor-based methods
% i.e: process_video('TD', 'HOSVD', 'dataset/demo.avi', 'output/demo_HOSVD.avi');
if(strcmp(method_id,'TD') || strcmp(method_id,'NTF'))
A = im2double(convert_video_to_3d(video));
T = tensor(A);
results = run_algorithm(method_id, algorithm_id, T, []);
movobj = convert_3dresults2mov([],results.L,results.S,results.O,size(T,3));
end
displog('Saving results...');
save_results(movobj,outFile);
displog('Process finished!');
displog(['CPU time: ' num2str(results.cputime)]);
stats.cputime = results.cputime; % Elapsed time for decomposition
stats.totaltime = toc(timerVal); % Total elapsed time
end