opencv/opencv_contrib

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

bitcurian opened this issue · 6 comments

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:
#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

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

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

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))

@kokoteen
OMG Thank you!!!!!

@kokoteen

Thanks a lot !

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.