Attribute Error: MultiTracker_create() Not Found in cv2 on Raspberry Pi

Viewed 8552

I am currently trying to set up the opencv trackers on a Raspberry Pi. However, when I use the MultiTracker_create() function, it gives me an Attribution Error:

multiTracker = cv2.MultiTracker_create()

AttributeError: module 'cv2.cv2' has no attribute 'MultiTracker_create'

The same code works on my computer, but when I try it on the Pi, it experiences the above error. I am currently using Python 3.5 on the Raspi with OpenCV 3.4.4. My computer uses Python 3.7 with OpenCV 3.4.1.

Thank you in advance for your help.

I have made sure that I am using the correct package: pip3 install opencv_contrib_python

I have also tried to look through the help(cv2) and could not find anything specific about the MultiTracker.

3 Answers

Just stumbled upon this myself. It appears that MultiTracker is no longer part of OpenCV 4.5.1, but you should be able to get it from the legacy package like this:

multiTracker = cv2.legacy.MultiTracker_create()

See https://docs.opencv.org/4.5.1/df/d4a/classcv_1_1legacy_1_1MultiTracker.html

Note that if you subsequently call multiTracker.add(...), you'll need to add the legacy version(s) of the trackers as well.

I've met the same problem and solved it. Maybe you can firstly do pip uninstall opecv-python and pip uninstall opencv-contrib-python, and then do pip install opencv-python==3.4.4.19 and pip install opencv-contrib-python==3.4.4.19. That's my solution, hope it's helpful.

This is an old thread, but I will add my answer, maybe helpful for someone facing same problem. cv2.MultiTracker_create() is missing from OpenCV documentation also on 4.5.1. [https://docs.opencv.org/4.5.1/d8/d77/classcv_1_1MultiTracker.html]

OpenCV contrib modules are known to be "unstable" which means that they can break or change. In my case, I had opencv-python and opencv-contrib-python both 4.5.2, but cv2.legacy.MultiTracker_create() was giving error.

Best solution is to uninstall opecv-python and opencv-contrib-python and reinstall version 4.4.0.46. This will solve the problem.

pip install opencv-python==4.4.0.46
pip install opencv-contrib-python==4.4.0.46
Related