Opencv-python: AttributeError: module 'cv2.cv2' has no attribute 'MultiTracker_create' with latest build

Created on 18 Jan 2021  路  2Comments  路  Source: opencv/opencv-python

Expected behaviour

Expected this code to return a multi tracker object:

import cv2
cv2.MultiTracker_create()

Actual behaviour

Throws the error:
AttributeError: module 'cv2.cv2' has no attribute 'MultiTracker_create'

Steps to reproduce

I installed the latest wheel of cv2 on a win10 x64 machine using pip in a venv (pip install opencv-contrib-python)

cv2.getVersionString() returns '4.5.1'

I can then import cv2 successfully in the python console, however cv2.MultiTracker_create() throws an error.

I completely uninstalled cv2 and installed again except with different version: pip install opencv-contrib-python~= 3.4.4.19
Since the function reportedly works in this version in a StackOverflow answer here

Once installed, the code runs successfully. So I assume it's a problem with this specific build of cv2 (i.e. version 4.5.1)

In the toolchain you have created, how do you select or deselect the modules that are installed form the C files? Is there a way that I can manually reinclude MultiTracker_create() back into my build, since don't have the expertise to build my own wheel. No worries if not, I'm just wondering why MultiTracker_create() was in an earlier build and not the most recent.

Thanks.

Issue submission checklist
  • [X] This is not a generic OpenCV usage question (looking for help for coding, other usage questions, homework etc.)

  • [X] I have read the README of this repository and understand that this repository provides only an automated build toolchain for OpenCV Python packages (there is no actual OpenCV code here)


  • [X] The issue is related to the build scripts in this repository, to the pre-built binaries or is a feature request (such as "please enable this additional dependency")

  • [x] I'm using the latest version of opencv-python

Most helpful comment

It's missing from OpenCV documentation also on 4.5.1: https://docs.opencv.org/4.5.1/d8/d77/classcv_1_1MultiTracker.html

But found in 4.5.0 and earlier: https://docs.opencv.org/4.5.0/d8/d77/classcv_1_1MultiTracker.html

This commit reveals that OpenCV developers changed the API between those versions: https://github.com/opencv/opencv_contrib/commit/80c197590ccfbd1dd9b4f54b250d26e06e840683

OpenCV contrib modules are known to be "unstable" which means that they can break or change. In this case the whole tacker API is being rewritten / modified, see: https://github.com/opencv/opencv_contrib/pull/2737 and https://github.com/opencv/opencv/issues/18481.

You can find the legacy multitracker API now from here, it has been preserved to maintain backward compatibility: https://docs.opencv.org/4.5.1/df/d4a/classcv_1_1legacy_1_1MultiTracker.html

Example:

Python 3.9.0 (tags/v3.9.0:9cf6752, Oct  5 2020, 15:34:40) [MSC v.1927 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import cv2
>>> cv2.legacy.MultiTracker_create()
<legacy_MultiTracker 00000203D312A9B0>

Please refer to the official OpenCV documentation in the future - make sure you have selected the correct version from dropdown menu. All the available OpenCV functions are clearly documented there: https://docs.opencv.org/4.5.1/df/d4a/classcv_1_1legacy_1_1MultiTracker.html

Note: Please do not refer to that Stack Overflow answer, it's completely wrong.

All 2 comments

It's missing from OpenCV documentation also on 4.5.1: https://docs.opencv.org/4.5.1/d8/d77/classcv_1_1MultiTracker.html

But found in 4.5.0 and earlier: https://docs.opencv.org/4.5.0/d8/d77/classcv_1_1MultiTracker.html

This commit reveals that OpenCV developers changed the API between those versions: https://github.com/opencv/opencv_contrib/commit/80c197590ccfbd1dd9b4f54b250d26e06e840683

OpenCV contrib modules are known to be "unstable" which means that they can break or change. In this case the whole tacker API is being rewritten / modified, see: https://github.com/opencv/opencv_contrib/pull/2737 and https://github.com/opencv/opencv/issues/18481.

You can find the legacy multitracker API now from here, it has been preserved to maintain backward compatibility: https://docs.opencv.org/4.5.1/df/d4a/classcv_1_1legacy_1_1MultiTracker.html

Example:

Python 3.9.0 (tags/v3.9.0:9cf6752, Oct  5 2020, 15:34:40) [MSC v.1927 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import cv2
>>> cv2.legacy.MultiTracker_create()
<legacy_MultiTracker 00000203D312A9B0>

Please refer to the official OpenCV documentation in the future - make sure you have selected the correct version from dropdown menu. All the available OpenCV functions are clearly documented there: https://docs.opencv.org/4.5.1/df/d4a/classcv_1_1legacy_1_1MultiTracker.html

Note: Please do not refer to that Stack Overflow answer, it's completely wrong.

Thank you very much of giving up your time to answer my question so well.

Was this page helpful?
0 / 5 - 0 ratings