Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Master obb #1791

Open
wants to merge 24 commits into
base: master
Choose a base branch
from
Open

Master obb #1791

wants to merge 24 commits into from

Conversation

LilBabines
Copy link

I propose an adaptation of OCSort to handle Oriented Bounding Boxes (OBB).
The bounding box (Bbox) format for the Kalman Filter is: c_x, c_y, w, h, angle.
All modifications are controlled by the OcSort.is_obb attribute. To enable OBB functionality, simply pass is_obb=True during the initialization of the OcSort tracker.

Main Modifications:

  1. KalmanBoxTrackerOBB Class

    • A new class KalmanBoxTrackerOBB is created based on the KalmanBoxTracker.
    • This class uses a new Kalman Filter implementation, KalmanFilterXYWHA, which extends KalmanFilterXYSR.
  2. BaseTracker Updates

    • Added an is_obb attribute to handle OBB-specific logic.
    • Updated asso_func_name :
      self.asso_func_name = asso_func + "_obb" if is_obb else asso_func
    • Adapted the BaseTracker.check_inputs() method to validate OBB inputs. OBB has 7 dimensions: c_x, c_y, w, h, angle, conf, cls (compared to 6 for standard bounding boxes).
  3. OcSORT Updates

    • Updated OcSORT.update() to handle the additional OBB dimension:
      • Adjusted indices dynamically: dets[:, idx + self.is_obb].
    • Dynamically chose between KalmanBoxTrackerOBB and KalmanBoxTracker based on self.is_obb.
    • Overwrote the plotting function to handle OBB visualization.
  4. Association Functions

    • Added two functions in AssociationFunction:
      • iou_batch_obb
      • centroid_batch_obb
    • Note: The iou_batch_obb function relies on an external helper function iou_obb_pair. This implementation could be improved for better integration.
  5. Other Changes

    • Updated k_previous_obs() to include a new is_obb argument.
    • Added a speed_direction_obb() function used by KalmanBoxTrackerOBB.

@mikel-brostrom
Copy link
Owner

mikel-brostrom commented Jan 18, 2025

Great job here @LilBabines! I would like to add some tests before merging this first version. Do you know if a obb tracking dataset exists? I think KITTI could be projected to the ground plane but that will require quite a lot of work. Would you be okay if I used the data you provided for the tests?

@mikel-brostrom
Copy link
Owner

I believe it does make sense to check wether the len of each prediction is 7 and activate the obb tracker version based on this?

@LilBabines
Copy link
Author

Hey @mikel-brostrom ! I don’t know of or use any public OBB dataset. I can try to find one to add a case study. I'll send a data sample once the upload is complete so you can test whatever you want for the OBB tracker.

The OBB-tracker version and the Tracker version are quite similar, which is why I tried to create an adaptive class. However, I think it makes sense to separate them, as it will also help clarify the code.

@LilBabines
Copy link
Author

FileSender, images + labels predictions.

@mikel-brostrom
Copy link
Owner

mikel-brostrom commented Jan 18, 2025

We could just do something similar as in here:

@pytest.mark.parametrize("tracker_type", PER_CLASS_TRACKERS)
def test_per_class_tracker_active_tracks(tracker_type):
tracker_conf = get_tracker_config(tracker_type)
tracker = create_tracker(
tracker_type=tracker_type,
tracker_config=tracker_conf,
reid_weights=WEIGHTS / 'mobilenetv2_x1_4_dukemtmcreid.pt',
device='cpu',
half=False,
per_class=True
)
rgb = np.random.randint(255, size=(640, 640, 3), dtype=np.uint8)
det = np.array([[144, 212, 578, 480, 0.82, 0],
[425, 281, 576, 472, 0.72, 65]])
embs = np.random.random(size=(2, 512))
tracker.update(det, rgb, embs)
# Check that tracks are created under the class tracks
assert tracker.per_class_active_tracks[0], "No active tracks for class 0"
assert tracker.per_class_active_tracks[65], "No active tracks for class 65"

but for obb. Let me know if you would be interested in adding this as well 😄 under tests/unit/test_trackers.py. That would complete this initial implementation.

@LilBabines
Copy link
Author

Yes, of course! I can perform some tests for obb and add them under tests/unit/test_trackers.py.

@mikel-brostrom
Copy link
Owner

Nice 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants