Reputation: 71
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.
Upvotes: 7
Views: 13811
Reputation: 136
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.
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
Upvotes: 5
Reputation: 1
I followed the instructions and install opencv 4.4.046 but now when I try to run the script, it shows import cv2 error showing: libhdf5_serial.so.103: cannot open shared object file: no such file or directory.
Upvotes: 0
Reputation: 35189
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.
Upvotes: 9
Reputation: 113
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.
Upvotes: 3