-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathgetDistMatrix.m
63 lines (55 loc) · 1.7 KB
/
getDistMatrix.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
function dmat = getDistMatrix(data, frame, ids, w)
% Returns matrix of distances
%
% Inputs:
% data - the struct that can be loaded from data.mat
% frame - frame number
% ids - previously computed labels
% w - vector of weights
%
% Outputs:
% dmat(i,j) = dist(next(i), prev(j));
xy = featureMatrix(data.Frames(frame), w);
xyP = featureMatrix(data.Frames(frame-1), w);
xyPP = xyP; %% prev-prev feature vectors
if frame>2
[~,permut] = ismember(ids{frame-2}, ids{frame-1}); % permutation
filter = find(permut>0); % remove non-zeros
permut = permut(filter);
xyPPN = featureMatrix(data.Frames(frame-2), w);
xyPP(:,permut) = xyPPN(:,filter); % permute it so we'll have corresponding fv's
end
% Set to a predicted position.
% The explanation is that dv = xa-2*x0-x1.
% So we set 5-th and 6-th lines of xyP to this value
xyP([5 6],:) = xyP([5 6],:)*2 - xyPP([5 6],:);
dmat = [];
for i=1:size(xy,2)
for j=1:size(xyP,2)
a = xy(:,i);
b = xyP(:,j);
dmat(i,j) = norm(a-b);
end
end
end
% returns matrix of features (nFeatures, nRectangles)
function fmat = featureMatrix(frameData, w)
nObjs = frameData.nObjects;
fmat = [];
for i = 1:nObjs
obj = frameData.objects(i);
fmat(:, i) = getFVector(obj, w);
end;
end
% returns one feature vector for one object
% w = [a;b;c;d] is a vector of weights
% a - stands for xy, b - scale, c - velocity, d - hog
function v = getFVector(obj, w)
box = obj.box;
r = [sscanf(box.xc, '%f'); sscanf(box.yc, '%f')];
s = [sscanf(box.w, '%f'); sscanf(box.h, '%f')];
%s = [str2double(box.w); str2double(box.h) ];
hog = obj.hog;
h = reshape(hog, 10*5*31, 1);
v = [r*w(1); s*w(2); r*w(3); h*w(4)];
end