0

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)
cou7inho
  • 11
  • 4
  • here's a C++ example. does that help? https://docs.opencv.org/4.x/d5/d07/tutorial_multitracker.html – Christoph Rackwitz Dec 12 '22 at 13:13
  • From what I understood they use `legacy::MultiTracker trackers;` to create the trackers. In python, I am using the same module `cv2.MultiTracker_create()`. I already tested `cv2.MultiTracker()`, `cv2.legacy.MultiTracker`, and `cv2.legacy.MultiTracker_create` but neither of these optionss are supported. – cou7inho Dec 12 '22 at 14:13
  • make sure you have the contrib variant installed, not the base variant of the package (and none concurrently, they conflict). -- the `..._create()` stuff is right. most opencv classes use this idiom of a factory method. -- I can call `trackers = cv.legacy.MultiTracker_create()` -- your question ends ("update:...") as if everything is resolved now. do you have any questions/issues left? remember, Stack Overflow encourages answering your own questions, in the SO question-answer format. someone else might find your question and would be happy to find the solution. – Christoph Rackwitz Dec 12 '22 at 15:13

1 Answers1

0

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)
cou7inho
  • 11
  • 4