1

I'm trying to perform a simple object detection using OpenCV in Python. My problem is that I cannot use TrackerMOSSE_create method as if it not exists.

I've only installed opencv-contrib-python package using pip install opencv-contrib-pythonand I'm aware that it cannot coexist with the opencv-python in one virtual env so I dont have that one.

I'm working on MAC and Python 3.8. There is a code below.

import cv2


print(cv2.__version__)

cap = cv2.VideoCapture(0)

tracker = cv2.TrackerMOSSE_create()


while True:

    timer = cv2.getTickCount()
    success, img = cap.read()

    fps = cv2.getTickFrequency() / (cv2.getTickCount() - timer)

    cv2.putText(img, str(int(fps)), (75, 50), cv2.FONT_ITALIC, 0.7, (0, 0, 255), 2)
    cv2.imshow("Tracking", img)

    if cv2.waitKey(1) & 0xff == ord('q'):
        break

The error I have:

Traceback (most recent call last):
  File "/Users/marcin94/PycharmProjects/tracker_objects/main.py", line 8, in <module>
    tracker = cv2.TrackerMOSSE_create()
AttributeError: module 'cv2.cv2' has no attribute 'TrackerMOSSE_create'
1

2 Answers 2

6

I had the same problem with Python 3.7, I think it has to do with the most recent version of opencv-contrib-python that pip automatically installs. So, I installed version 3.4.13.47 from this overview.

pip install opencv-contrib-python==3.4.13.47

Then it worked for me. Good luck!

Sign up to request clarification or add additional context in comments.

Comments

2

Just change cv2.TrackerMOSSE_create() to cv2.legacy.TrackerMOSSE_create() and it should work.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.