-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdemo.m
74 lines (64 loc) · 2.53 KB
/
demo.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
% Distribution code Version 1.0 -- Oct 12, 2013 by Cewu Lu
%
% The Code is to demo Sparse Combination in our Avenue Dataset, based on the method described in the following paper
% [1] "Abnormal Event Detection at 150 FPS in Matlab" , Cewu Lu, Jianping Shi, Jiaya Jia,
% International Conference on Computer Vision, (ICCV), 2013
%
% The code and the algorithm are for non-commercial use only.
%% abnormal event detection in testing
addpath('functions')
addpath('data')
load('data/sparse_combinations/Tw.mat','Tw');
load('data/sparse_combinations/R.mat','R');
params.H = 120; % loaded video height size
params.W = 160; % loaded video width size
params.patchWin = 10; % 3D patch spatial size
params.tprLen = 5; % 3D patch temporal length
params.BKH = 12; % region number in height
params.BKW = 16; % region number in width
params.srs = 5; % spatial sampling rate in trainning video volume
params.trs = 2; % temporal sampling rate in trainning video volume
params.PCAdim = 100; % PCA Compression dimension
params.MT_thr = 5; % 3D patch selecting threshold
H = params.H;
W = params.W;
patchWin = params.patchWin;
tprLen = params.tprLen;
BKH = params.BKH;
BKW = params.BKW;
PCAdim = params.PCAdim;
ThrTest = 0.20;
ThrMotionVol = 5;
volFrame = 5; % the number of video we test
%volFrame = 20;
%volFrame = 21;
load(['data/testing_vol/vol', sprintf('%.2d', volFrame),'.mat']);
imgVol = im2double(vol);
t1 = tic;
volBlur = imgVol;
blurKer = fspecial('gaussian', [3,3], 1);
mask = conv2(ones(H,W), blurKer,'same');
for pp = 1 : size(imgVol,3)
volBlur(:,:,pp) = conv2(volBlur(:,:,pp), blurKer, 'same')./mask;
end
feaVol = abs(volBlur(:,:,1:(end-1)) - volBlur(:,:,2:end));
[feaPCA, LocV3] = test_features(feaVol, Tw, ThrMotionVol, params);
Err = recError(feaPCA, R, ThrTest);
AbEvent = zeros(BKH, BKW, size(imgVol,3));
for ii = 1 : length(Err)
AbEvent(LocV3(1,ii),LocV3(2,ii),LocV3(3,ii)) = Err(ii);
end
AbEvent3 = smooth3( AbEvent, 'box', 5);
% AbEvent3 already can indicate abnormalities in each region, so testing stops here.
t2 = toc(t1);
fprintf('we can achieve %d FPS in %d th video \n', round(size(imgVol,3)/t2), volFrame);
%% video demo
optThr = 0.08;
AbEventShow3 = imgVol;
for frameID = 1 : size(imgVol,3)
AbEventShow3(:,:,frameID) = double(imresize(AbEvent3(:,:,frameID) ,[H, W], 'nearest') > optThr) ;
end
for frameID = 1 : size(imgVol,3)
imshow([imgVol(:,:,frameID), AbEventShow3(:,:,frameID)]);
getframe;
end