Solving Python OpenCV AttributeError module ‘cv2.cv2’ has no attribute ‘Tracker_create’

Python OpenCV AttributeError module ‘cv2.cv2’ has no attribute ‘Tracker_create’ is an error which occurs when you have a faulty installation of opencv or when opencv dependencies are not installed. 

In today’s article I am going to present a set of possible solutions. In order to deal with a confusing error and explain why it takes place.

Exploring Python OpenCV AttributeError module ‘cv2.cv2’ has no attribute ‘Tracker_create’

This is an error which occurs when you have a faulty installation of opencv or when opencv dependencies are not installed. 

Beware of mixing between errors. Double check if the error message looks like the error message bellow, then continue.

                                                                       #
AttributeError: module 'cv2.cv2' has no attribute 'Tracker_create'
                                                                       #

Bellow, I prepared two methods that have worked for me, I hope you can follow them and solve the issue.

Solution 1 : use cv2.legacy_TrackerMOSSE.create() instead of using cv2.TrackerMOSSE.create()

The first solution is to use cv2.legacy_TrackerMOSSE.create() instead of using cv2.TrackerMOSSE.create()

So you should essentially replace

                                                                       #
tracker = cv2.legacy_TrackerMOSSE.create()
                                                                       #

with the line

                                                                       #
tracker = cv2.TrackerMOSSE.create()
                                                                       #

The TrackerMOSSE Class presents the MOSSE tracker which works with grayscale images.

I hope this methods works for you, If it does not please check out the following method.

Solution 2 : Correctly install opencv-contrib-python

The fastest and clearer method to solve the error is to install opencv-contrib-python.

It is better to do it as the root user using the pip package manager

                                                                       #
sudo pip install opencv-contrib-python
                                                                       #

opencv-contrib-python offers Pre-built CPU-only OpenCV packages for Python.

I hope the methods above have been helpful. Thank you so much for reading this post to the end.

Summing-up : 

This is the end of our article, I hope the solutions I presented worked for you, Learning Python is a fun journey, do not let the errors discourage you. Keep coding and cheers.

Thank you for reading, keep coding and cheers. If you want to learn more about Python, please check out the Python Documentation : https://docs.python.org/3/