Skip to content

Commit

Permalink
fixing largest bbox bug in yolo tracker
Browse files Browse the repository at this point in the history
  • Loading branch information
igormaurell committed Jul 6, 2023
1 parent 4f21cbc commit b159d7e
Showing 1 changed file with 19 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ def __init__(self,state = True):
DeepOCSORT = boxmot.DeepOCSORT
if self.tracking_on_init:
self.startTracking(None)

self.lastTrack = perf_counter()

rospy.loginfo("Yolo Tracker Recognition Node started")

Expand All @@ -60,8 +62,8 @@ def serverStop(self, req):

def startTracking(self, req):
self.loadTrackerModel()
self.trackID = -2
self.lastTrack = -self.max_time
self.trackID = -1
self.lastTrack = perf_counter()
self.tracking = True
rospy.loginfo("Tracking started!!!")
return EmptyResponse()
Expand Down Expand Up @@ -145,6 +147,10 @@ def callback(self, *args):

tracked_box = None
now = perf_counter()
is_aged = (now - self.lastTrack >= self.max_time)
is_id_found = False
previus_size = float("-inf")
new_id = -1
# descriptions = []
for i, box in enumerate(bboxs):
description = Description2D()
Expand All @@ -165,51 +171,40 @@ def callback(self, *args):
description.id = i

box_label = ""
previus_size = float("-inf")
if tracking:
description.global_id = ID
if description.label == "person":
people_ids.append(ID)

box_label = f"ID:{ID} "
size = description.bbox.size_x * description.bbox.size_y
# if ID == self.trackID or \
# self.trackID == -1 or \
# (perf_counter() - self.lastTrack >= self.max_time and \
# (tracked_box == None or\
# size > previus_size)):

# self.trackID = ID
# previus_size = size
# tracked_box = description

if ID == self.trackID:
self.trackID = ID
previus_size = size
tracked_box = description
self.lastTrack = perf_counter()
elif perf_counter() - self.lastTrack >= self.max_time and (tracked_box == None or size > previus_size):
previus_size = size
is_id_found = True
tracked_box = description
self.trackID = ID


if (not is_id_found) and (is_aged or self.trackID == -1):
if tracked_box is None or size > previus_size:
previus_size = size
tracked_box = description
new_id = ID

recognition.descriptions.append(description)

cv.rectangle(debug_img,(int(X1),int(Y1)), (int(X2),int(Y2)),(0,0,255),thickness=2)
cv.putText(debug_img,f"{box_label}{self.model.names[clss]}:{score:.2f}", (int(X1), int(Y1)), cv.FONT_HERSHEY_SIMPLEX,0.75,(0,0,255),thickness=2)
if tracked_box != None:
self.lastTrack = perf_counter()


track_recognition = Recognitions2D()
track_recognition.header = HEADER
tracked_description : Description2D = deepcopy(tracked_box)
if tracked_box != None:
if tracked_box is not None:
track_recognition.header = recognition.header
track_recognition.image_rgb = recognition.image_rgb
track_recognition.image_depth = recognition.image_depth
track_recognition.camera_info = recognition.camera_info
tracked_description.type = Description2D.DETECTION
if not is_id_found:
self.trackID = new_id
# recognition.descriptions.append(tracked_box)
self.lastTrack = now
cv.rectangle(debug_img,(int(tracked_box.bbox.center.x-tracked_box.bbox.size_x/2),\
Expand Down

0 comments on commit b159d7e

Please sign in to comment.