@@ -23,15 +23,17 @@ class SingleKFUndirectedObjectTracker(object):
23
23
R_diag - diagonale of R matrix [Rx, Ry]
24
24
k_decay - coefficien of speed reduction
25
25
color - (r, g, b) each normlized on 1
26
+ score - initial score for object
26
27
'''
27
- def __init__ (self , x_start , t_start , Q_diag , R_diag , k_decay , color ):
28
+ def __init__ (self , x_start , t_start , Q_diag , R_diag , k_decay , color , score ):
28
29
29
30
self .x = np .array ([x_start [0 ], x_start [1 ], 0.0 , 0.0 ])
30
31
self .last_t = t_start
31
32
self .last_upd_t = t_start
32
33
self .Q = np .diag (Q_diag )
33
34
self .R = np .diag (R_diag )
34
35
self .k_decay = k_decay
36
+ self .score = score
35
37
36
38
self .color = color
37
39
@@ -68,12 +70,15 @@ def predict(self, t):
68
70
69
71
self .predict_steps += 1
70
72
73
+ self .score *= self .k_decay
74
+
71
75
72
76
'''
73
77
z - measured x, y values
74
78
t - time stamp for update, seconds
79
+ score - score of new measurment
75
80
'''
76
- def update (self , z , t ):
81
+ def update (self , z , t , score ):
77
82
self .last_upd_t = t
78
83
79
84
y = z - np .matmul (self .H , self .x )
@@ -89,6 +94,8 @@ def update(self, z, t):
89
94
self .track .append (self .x .copy ())
90
95
91
96
self .predict_steps = 0
97
+
98
+ self .score = score
92
99
93
100
class RobotKFUndirectedObjectTracker (object ):
94
101
@@ -125,6 +132,8 @@ def __init__(self):
125
132
self .min_score = rospy .get_param ('~min_score' , 0 )
126
133
self .min_score_soft = rospy .get_param ('~min_score_soft' , self .min_score )
127
134
135
+ self .sort_by_score = rospy .get_param ("~sort_by_score" , False )
136
+
128
137
self .colors = []
129
138
for c in plt .rcParams ['axes.prop_cycle' ].by_key ()['color' ]:
130
139
#print(type(mpl.colors.to_rgb(c)))
@@ -157,7 +166,7 @@ def process(self, event):
157
166
158
167
#rospy.logwarn(f"{name} {i} {kf.x} {kf.P}")
159
168
for index in sorted (remove_index , reverse = True ):
160
- del kfs [index ]
169
+ del kfs [index ]
161
170
162
171
self .to_marker_array ()
163
172
self .to_tf ()
@@ -166,7 +175,15 @@ def process(self, event):
166
175
167
176
def to_tf (self ):
168
177
now = rospy .Time .now ()
169
- for name , kfs in self .objects_to_KFs .items ():
178
+
179
+ if self .sort_by_score :
180
+ mass = sorted (list (self .objects_to_KFs .items ()), key = lambda x : x [1 ].score )
181
+ else :
182
+ mass = list (self .objects_to_KFs .items ())
183
+
184
+ #for name, kfs in self.objects_to_KFs.items():
185
+ for name , kfs in mass :
186
+
170
187
for i , kf in enumerate (kfs ):
171
188
172
189
t = TransformStamped ()
@@ -188,7 +205,13 @@ def to_tracked_object_array(self):
188
205
msg_array = TrackedObjectArray ()
189
206
msg_array .header .stamp = rospy .Time .now ()
190
207
msg_array .header .frame_id = self .target_frame
191
- for name , kfs in self .objects_to_KFs .items ():
208
+
209
+ if self .sort_by_score :
210
+ mass = sorted (list (self .objects_to_KFs .items ()), key = lambda x : x [1 ].score )
211
+ else :
212
+ mass = list (self .objects_to_KFs .items ())
213
+ for name , kfs in mass :
214
+ #for name, kfs in self.objects_to_KFs.items():
192
215
for i , kf in enumerate (kfs ):
193
216
msg = TrackedObject ()
194
217
msg .child_frame_id = self .tf_pub_prefix + name + f'_{ i } '
@@ -220,7 +243,12 @@ def to_tracked_object_array(self):
220
243
def to_marker_array (self ):
221
244
now = rospy .Time .now ()
222
245
marker_array = MarkerArray ()
223
- for name , kfs in self .objects_to_KFs .items ():
246
+ if self .sort_by_score :
247
+ mass = sorted (list (self .objects_to_KFs .items ()), key = lambda x : x [1 ].score )
248
+ else :
249
+ mass = list (self .objects_to_KFs .items ())
250
+ for name , kfs in mass :
251
+ #for name, kfs in self.objects_to_KFs.items():
224
252
i = - 1
225
253
for i , kf in enumerate (kfs ):
226
254
# TEXT
0 commit comments