McMasterAI / TrafficTracker

A street traffic counter that provides efficient and ethical modelling of how people engage and interact within a given public space.
MIT License
7 stars 2 forks source link

Correct Bounding Box Issue #82

Open cczarnuch opened 3 years ago

cczarnuch commented 3 years ago

YOLOv5 produces output bounding boxes of the format TLWH (top-left, width, height). The bounding boxes deepsort takes as input are of the format XYWH (center x, y, width, height). During the deepsort run() function the bounding boxes' features are determined using the XYWH format, then they are converted to TLWH format. The TLWH format is used to create a Detection object which is updated in the tracker.predict() method. The output boxes are saved as a TLWH format bounding box and then converted to XYWH format bounding box.

The goal of this story will be to not only correct the bounding boxes, but also to ensure that the least number of conversions between boxes are done. Another goal would be to remove unused conversion functions.

icecap360 commented 3 years ago

Here are some things that I have found in chronological order:

  1. In detections.py, the method 'yolo_predict', I could not figure out the format of the output.
  2. In detections.py the method 'yolo_predict', calls method nm_suppression (defined in general.py), which states that it takes in images of format xywh, converts to xyxy. It then does some computation on xyxy, and outputs in xyxy.
  3. In detections.py in method 'yolo_predict', a method is called that scales the xyxy coordinates.
  4. In detections.py in method 'yolo_predict', WE convert xyxy to tlwh.
  5. In deep_sort/deep_sort.py in method 'update', WE treat the coordinates as though they are in xywh, when they are in tlwh! So we convert remove the xywh to tlwh convesion.
  6. In deep_sort/deep_sort.py in method 'update', WE convert the outputs of the tracker from tlwh to xywh and return them.
  7. In trafficrtracker.py in method 'run', WE convert the outputs of the step 6 (from the update method) to tlwh format.

In the attempt1 branch I just created, I left detections.py alone, but fixed the method 'update' and I removed the useless converion of tlwh-xywh-tlwh ( found in steps 6-7)

  1. Fixed 'update' so that it treats the inputs as though they are in tlwh format.
  2. Made 'update' output in tlwh.
  3. Updated traffictracker.py to treat the outputs of update as though they were in xywh.