opencv / opencv_contrib

Repository for OpenCV's extra modules
Apache License 2.0
9.36k stars 5.75k forks source link

[Feature Request]: remove() method in MultiTracker() #2377

Open bitcurian opened 4 years ago

bitcurian commented 4 years ago

The MultiTracker class in tracker.hpp is great for a quick demo of multi-object tracking using different trackers and objects.

I understand that it's a naive implementation and has not been optimized. However there is atleast one critical function that it requires, namely a method to remove objects that are not in the frame

Currently, the only way to do this is to use clear() and then reinitialize the MultiTracker() class with the new set of (tracker,bbox) pairs.

Multi-object tracking is certainly not an easy problem, especially with occlusion. However there needs to be , at the very least, a method to manually remove (tracker,object) pairs that are not being tracked.

I'd also suggest adding an experimental method to remove objects that are not in the frame. If the object has a fixed size and is lost, it could be removed from the tracker if the bounding box area increases beyond a certain threshold or the regressor's prediction is below a specific threshold. It could be invoked by specific flags in the argument. This would certainly be preferable to the alternative of having the tracker track another similar object.

Other Issue which addressed this: https://github.com/opencv/opencv_contrib/issues/2368

Class reference docs : https://docs.opencv.org/master/d8/d77/classcv_1_1MultiTracker.html

OpenCV Q&A : https://answers.opencv.org/question/140415/how-to-delete-an-object-from-multitracker/

Thanking you in advance, Sincerely, Vj

dkout commented 4 years ago

Plus one for this feature, it would be very useful to have!

Damon2019 commented 3 years ago

I also met the same problem. Have you solved it?

kokoteen commented 3 years ago

found a hacky solution that could work on some problems

(tracking_ok, boxes) = trackers.update(frame)

if tracking_ok:
         # some code
else:
        trackers_arr = np.array(trackers.getObjects())
        idx = np.where(trackers_arr.sum(axis=1)!=0)[0]
        trackers_arr=trackers_arr[idx]
        ID_array = ID_array[idx] 
        trackers = cv2.legacy.MultiTracker_create()
        for i in trackers_arr:
            tracker = cv2.legacy.TrackerCSRT_create()
            trackers.add(tracker, frame, tuple(i))
HelenTsvetkova commented 2 years ago

@kokoteen OMG Thank you!!!!!

zain18jan2000 commented 2 years ago

@kokoteen

Thanks a lot !

TByte007 commented 1 year ago

remove() and then a way set of a new bounding box too for a specific tracker and way to find which specific tracker failed. The current multi tracker is some kind of a demo at best.