-
Notifications
You must be signed in to change notification settings - Fork 2
/
blob_state_reorder.m
100 lines (98 loc) · 3.27 KB
/
blob_state_reorder.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
% * ----------------------------------------------------------------------
% * Function Name : blob_state_reorder()
% * Description : To reorder blobs based on minimum distance
% * criteria
% * ---------------+-----+-----+-----+----------------------------------
% * Name | I/P | O/P | I/O | Purpose
% * ---------------+-----+-----+-----+----------------------------------
% * blob_state | | | X | Blob State Structure pointer
% * blob_data | | | X | Blob data Structure pointer
% * nw_order | | X | | New order of the blobs
% *-----------------------------------------------------------------------
function [nw_order,blob_state,blob_data] = blob_state_reorder...
(blob_state,blob_data, score)
%Loading state variables to local variables
cur_cnt = length(blob_state.Area_cur);
pst_cnt = length(blob_state.Area_pst);
BB_Box_cur = blob_state.BB_Box_cur;
BB_Box_pst = blob_state.BB_Box_pst;
C_pst = blob_state.Centroid_pst;
C_cur = blob_state.Centroid_cur;
A_pst = blob_state.Area_pst;
A_cur = blob_state.Area_cur;
%Declaring new variables
nw_cnt = max(cur_cnt, pst_cnt);
C_new = zeros(nw_cnt,2);
A_new = zeros(1,nw_cnt);
BB_Box_new = zeros(nw_cnt,4);
nw_order = zeros(nw_cnt,1);
dist_parm = zeros(pst_cnt,1);
D_cur = zeros(cur_cnt,2);
D_pst = zeros(pst_cnt,2);
%Initializations
k = 1;
Th1 = 0;
d_cnt = 1;
%Reording the blobs based on min distance between frames
while(k <= pst_cnt)
d_prm = 100*ones(1,cur_cnt);
for i = 1:cur_cnt
if(D_cur(i,1) == 0)
d_prm(i) = score(i,k);
end
end
[min_d, min_i] = min(d_prm);
dist_parm(k) = min_d;
if(min_d < Th1)
C_new(d_cnt,:) = C_cur(min_i,:);
A_new(d_cnt) = A_cur(min_i);
BB_Box_new(d_cnt,:) = BB_Box_cur(min_i,:);
nw_order(d_cnt) = k;
D_cur(min_i,:) = [-1,-1];
D_pst(k,:)= [-1,-1];% as a marker to know if the value is set
%Updating Detect Counter
blob_data(k).detect_cnt = blob_data(k).detect_cnt+1;
d_cnt= d_cnt+1;
end
k = k+1;
end
m = 1;
if(pst_cnt > cur_cnt)
for i = 1:pst_cnt
if(D_pst(i,1) == 0)
nw_order(d_cnt-1+m) = i;
C_new(d_cnt-1+m,:) = C_pst(i,:);
A_new(d_cnt-1+m) = A_pst(i);
BB_Box_new(d_cnt-1+m,:) = BB_Box_pst(i,:);
%Updating Lost Counter
blob_data(i).lost_cnt = blob_data(i).lost_cnt+1;
m=m+1;
end
end
elseif(pst_cnt < cur_cnt)
for i = 1:cur_cnt
if(D_cur(i,1) == 0)
nw_order(d_cnt-1+m) = d_cnt-1+m;
C_new(d_cnt-1+m,:) = C_cur(i,:);
A_new(d_cnt-1+m) = A_cur(i);
BB_Box_new(d_cnt-1+m,:) = BB_Box_cur(i,:);
m=m+1;
end
end
else
for i = 1:cur_cnt
if(D_cur(i,1) == 0)
nw_order(d_cnt-1+m) = i;
C_new(d_cnt-1+m,:) = C_cur(i,:);
A_new(d_cnt-1+m) = A_cur(i);
BB_Box_new(d_cnt-1+m,:) = BB_Box_cur(i,:);
%Updating Lost Counter
blob_data(i).lost_cnt = blob_data(i).lost_cnt+1;
m=m+1;
end
end
end
% Loading new found blob locations to the filter state
blob_state.BB_Box_new =BB_Box_new;
blob_state.Centroid_new =C_new;
blob_state.Area_new =A_new;