Home > Software design >  How to use Multi Tracker with OpenCV 4.6?
How to use Multi Tracker with OpenCV 4.6?

Time:12-15

I am trying to track multiple objects and to do so I am using a Multi Tracker. This is the part of my code that should initialize the tracker:

multiTracker = cv2.MultiTracker_create()

for box in boxes:
  multiTracker.add(cv2.TrackerKCF_create(), frame, box)

When I run the code the following error appears:

    multiTracker = cv2.MultiTracker_create()
AttributeError: module 'cv2' has no attribute 'MultiTracker_create'

I already try to use cv2.MultiTracker instead of cv2.MultiTracker_createbut nothing works. I already tried cv2.legacy.MultiTrackerbut, again, it didn't work. Is there any way to use this MultiTracker with OpenCV 4.6? If not what's the new alternative? I did some research but I didn't find relevant information.

UPDATE: After adding legacy to cv2.TrackerKCF_create() the error disappeared.

multiTracker = cv2.legacy.MultiTracker_create()

for box in boxes:
  multiTracker.add(cv2.legacy.TrackerKCF_create(), frame, box)

CodePudding user response:

After some changes, I founs a solution. I am using the TrackerKCF, with OpenCV 4.6, and this is my solution:

multiTracker = cv2.legacy.MultiTracker_create()

for box in boxes:
  multiTracker.add(cv2.legacy.TrackerKCF_create(), frame, box)
  • Related