0
import cv2

if __name__ == "__main__":
    major_v, minor_v, subminor_v = (cv2.__version__).split('.')
    # >>> 4.6.0
    tracker = cv2.TrackerKCF_create()
    # >>> AttributeError: module 'cv2' has no attribute 'TrackerKCF_create'

As the code above shows, when running this these are the results I get (I have tried this with other trackers in cv2 and other than TrackerMIL_create all trackers that are supposed to be included are giving me this error. I used pip install opencv-python, pip install opencv-contrib-python, and pip install opencv-contrib-python-headless on my terminal to try and install opencv. I haven't run into any other issues with cv2 attributes (such as imread, imshow, resize) but the trackers are giving me a hard time and I was wondering if there is anything I am doing wrong from the start. Thanks.

ddelarue
  • 51
  • 5
  • Did you install `opencv-contrib-python`? `TrackerKCF_create()` is not in the regular `opencv-python` module. – wkl Jun 23 '22 at 21:13
  • Yes, I installed `opencv-contrib-python`, `opencv-python`, and `opencv-contrib-python-headless` and nothing seems to work – ddelarue Jun 23 '22 at 21:14
  • If you still have everything installed, remove everything and then reinstall `opencv-contrib-python`. The packages can conflict with one another. `pip uninstall opencv-contrib-python opencv-python opencv-contrib-python-headless && pip install opencv-contrib-python` – wkl Jun 23 '22 at 21:17
  • @wkl -- You could consider making this an answer. – BrokenBenchmark Jun 24 '22 at 01:42

1 Answers1

4

Remove everything and then reinstall opencv-contrib-python. The packages can conflict with one another. pip uninstall opencv-contrib-python opencv-python opencv-contrib-python-headless && pip install opencv-contrib-python

ddelarue
  • 51
  • 5