-
Notifications
You must be signed in to change notification settings - Fork 168
/
apply_motion_prediction.m
53 lines (48 loc) · 1.27 KB
/
apply_motion_prediction.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
% --------------------------------------------------------
% MDP Tracking
% Copyright (c) 2015 CVGL Stanford
% Licensed under The MIT License [see LICENSE for details]
% Written by Yu Xiang
% --------------------------------------------------------
%
% apply motion models to predict the next locations of the targets
function prediction = apply_motion_prediction(fr_current, tracker)
% apply motion model and predict next location
dres = tracker.dres;
index = find(dres.state == 2);
dres = sub(dres, index);
cx = dres.x + dres.w/2;
cy = dres.y + dres.h/2;
fr = double(dres.fr);
% only use the past 10 frames
num = numel(fr);
K = 10;
if num > K
cx = cx(num-K+1:num);
cy = cy(num-K+1:num);
fr = fr(num-K+1:num);
end
fr_current = double(fr_current);
% compute velocity
vx = 0;
vy = 0;
num = numel(cx);
count = 0;
for j = 2:num
vx = vx + (cx(j)-cx(j-1)) / (fr(j) - fr(j-1));
vy = vy + (cy(j)-cy(j-1)) / (fr(j) - fr(j-1));
count = count + 1;
end
if count
vx = vx / count;
vy = vy / count;
end
if isempty(cx) == 1
dres = tracker.dres;
cx_new = dres.x(end) + dres.w(end)/2;
cy_new = dres.y(end) + dres.h(end)/2;
else
cx_new = cx(end) + vx * (fr_current + 1 - fr(end));
cy_new = cy(end) + vy * (fr_current + 1 - fr(end));
end
prediction = [cx_new cy_new];