MultiTracker_create not in module of openCV vers 4.11.0 (openCV_contrib_python)

even though the documentation of openCV 4.11.0 says it has the class / function MultiTracker_create() , the cv2.getBuildInformation() says AttributeError: module ‘cv2’ has no attribute ‘MultiTracker_create’ How come the atribute is not there? the print(cv2.version) confirms that it is vers 4.11.0 that is installed. I have exhausted all searches in google and used GitHub Copilot to work through this with me. Tried to reinstall openCV-contrib and no success. always missing in module. Also I have tried the legacy options - not working. Any suggestions?

however, it does not confirm, that you installed the contrib modules. please:

pip uninstall opencv-python               # cleanup
pip install opencv-contrib-python         # re-install

tracker = cv2.legacy.MultiTracker_create() # MUST use legacy namespace

p.s.: i personally find the MultiTracker interface quite retarded
(as you can never tell, which member failed or succeeded)
rather be bold, and use your own array of trackers !

yes that is what i did with the Centroid tracker, but it is not good at occlusion so I want to try the TrackerCSRT_create tracker with multitracker or implement my own array of trackers, but it is the same error I get with TrackerCSRT - attribute not found in module

>>> help(cv2.legacy) 
...
CLASSES
    cv2.Algorithm(builtins.object)
        MultiTracker
        Tracker
            TrackerBoosting
            TrackerCSRT
            TrackerKCF
            TrackerMIL
            TrackerMOSSE
            TrackerMedianFlow
            TrackerTLD

so, obviously it needs:

cv2.legacy.TrackerCSRT_create()

yes but the problem is that the cv2 installation does not have the legacy name space either (or the module)
see error: print(cv2.legacy)
AttributeError: module ‘cv2’ has no attribute ‘legacy’

go & re-install, now properly
make sure:

  • you only have 1 version of python/cv2
  • you really uninstalled any previous cv2

Thank you for your time -
here is a confirmation of the “real uninstall” and installation
PS C:\Users\Daddi\source\repos\FishVideoTracker> pip uninstall opencv-contrib-python
Found existing installation: opencv-contrib-python 4.11.0.86
Uninstalling opencv-contrib-python-4.11.0.86:
Would remove:
c:\users\daddi\appdata\roaming\python\python37\site-packages\cv2*
c:\users\daddi\appdata\roaming\python\python37\site-packages\opencv_contrib_python-4.11.0.86.dist-info*
Proceed (Y/n)? y
Successfully uninstalled opencv-contrib-python-4.11.0.86

Profile of new intallation:
General configuration for OpenCV 4.11.0 =====================================
Version control: 4.11.0

Platform:
Timestamp: 2025-01-16T09:57:07Z
Host: Windows 10.0.17763 AMD64
CMake: 3.24.2
CMake generator: Visual Studio 14 2015
CMake build tool: MSBuild.exe
MSVC: 1900
Configuration: Debug Release
Algorithm Hint: ALGO_HINT_ACCURATE

CPU/HW features:
Baseline: SSE SSE2 SSE3
requested: SSE3
Dispatched code generation: SSE4_1 SSE4_2 AVX FP16 AVX2
requested: SSE4_1 SSE4_2 AVX FP16 AVX2 AVX512_SKX
SSE4_1 (16 files): + SSSE3 SSE4_1
SSE4_2 (1 files): + SSSE3 SSE4_1 POPCNT SSE4_2
AVX (8 files): + SSSE3 SSE4_1 POPCNT SSE4_2 AVX
FP16 (0 files): + SSSE3 SSE4_1 POPCNT SSE4_2 AVX FP16
AVX2 (36 files): + SSSE3 SSE4_1 POPCNT SSE4_2 AVX FP16 AVX2 FMA3


PS C:\Users\Daddi\source\repos\FishVideoTracker> pip list
Package Version


cycler 0.11.0
fonttools 4.38.0
imageio 2.31.2
kiwisolver 1.4.5
matplotlib 3.5.3
networkx 2.6.3
numpy 1.21.6
opencv-contrib-python 4.11.0.86
packaging 24.0
Pillow 9.5.0
pip 24.0
pyparsing 3.1.4
pypylon 3.0.1
python-dateutil 2.9.0.post0
PyWavelets 1.3.0
scikit-image 0.19.3
scipy 1.7.3
setuptools 47.1.0
six 1.17.0
tifffile 2021.11.2

that pip list looks like you’ve got the package situation right.

are there any venvs/virtualenvs/… involved? do you use PyCharm at all, which creates envs on its own?

After some googl’ing and reading on StackOverflow I saw that some people have been downgrading their version of openCV, and so i did, went from 4.11 to 4.3.0.36 and “vola” the attributes are now available and the Multitracker and the CSRTTracker come alife. So this must mean that these trackers have been removed from 4.11 and even erlier. Why - are they no good or what? I am now struggeling a little with the implementation of the multitracker, it is very slow so there is something wrong with my way of using it - do you have any experience with it or can you point to samples where it is used. I need a tracker that is good on occlusion, specially two objects crossing each others path and seperating again. Speed is rather high 2 pxl/ms in a field of 700 x 500 pxl. but in the end the question is why are the Trackers not available in vers 4.11

bs. all fine for me. you’re doing something wrong. please look again at samples/tests.
if those fail, your local install is broken

This is my setup with OpenCV 4.11.

Clearly, this stuff is there, but if you ask for it in the wrong place, it’s “not there”.

Since this does work somewhere (e.g. on my computer, and anyone else who’s using that stuff without issue), the issue is purely with your setup, or what you claim to be doing but might not actually be doing as you claim.

>>> cv.MultiTracker_create
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: module 'cv2' has no attribute 'MultiTracker_create'
>>> cv.legacy.MultiTracker_create
<built-in function MultiTracker_create>
>>>
1 Like