"module" object has no attribute 'TrackerKFC_create'

Hi guys,

I am trying to use this script in python: https://www.learnopencv.com/object-tracking-using-opencv-cpp-python/

The problem is when I’m running I have this error occuring:

Traceback (most recent call last):
  File "./Tracking.py", line 24, in <module>
    tracker = cv2.TrackerKCF_create()
AttributeError: 'module' object has no attribute 'TrackerKCF_create'

I have python 2.7.12 and python 3.5.2 on the Jetson as well as OpenCV 3.4.0.

Some post on forums tell about a “opencv-contrib-python” package that is not included and should be added, but when I try to find it using “pip install” it tells me this:

Collecting opencv-contrib-python
  Could not find a version that satisfies the requirement opencv-contrib-python (from versions: )
No matching distribution found for opencv-contrib-python

I don’t really know what to do then…

Thank you in advance

Hi vincent.dufour,

You can build opencv with contrib enabled.
But, it requires 15 GB disk space for build.

If you use JetPack 3.2/3.2.1 with Python2.7, you can install the package I built.
https://github.com/naisy/JetsonTX2/tree/JetPack3.2_python2.7/JetPack3.2/python2.7/binary

apt-get install -y build-essential cmake libeigen3-dev libatlas-base-dev gfortran git wget libavformat-dev libavcodec-dev libswscale-dev libavresample-dev ffmpeg pkg-config unzip qtbase5-dev libgtk-3-dev libdc1394-22 libdc1394-22-dev libjpeg-dev libpng12-dev libtiff5-dev libjasper-dev libavcodec-dev libavformat-dev libswscale-dev libxine2-dev libgstreamer1.0-dev libgstreamer-plugins-base1.0-dev libv4l-dev libtbb-dev libfaac-dev libmp3lame-dev libopencore-amrnb-dev libopencore-amrwb-dev libtheora-dev libvorbis-dev libxvidcore-dev v4l-utils liblapacke-dev libopenblas-dev checkinstall libgdal-dev libgphoto2-dev

dpkg -i opencv-3.4.1.deb

For TX2 webcam, I fixed the python code.

# Read video
    video = cv2.VideoCapture(1)

It works very well.

Thank you for your answer naisy,

here is what I obtain when I execute your command:

nvidia@tegra-ubuntu:~$ sudo dpkg -i opencv-3.4.1.deb
[sudo] password for nvidia: 
(Reading database ... 191693 files and directories currently installed.)
Preparing to unpack opencv-3.4.1.deb ...
Unpacking opencv (3.4.1) over (3.4.1) ...
Setting up opencv (3.4.1) ...
nvidia@tegra-ubuntu:~$

Then nothing more happen, even after reboot nothing special I still have the same error about the module object with no attribute…

I even reinstalled opencv3.4.0 following https://www.pyimagesearch.com/2016/10/24/ubuntu-16-04-how-to-install-opencv/ and https://jkjung-avt.github.io/opencv3-on-tx2/ and adding

-D OPENCV_EXTRA_MODULES_PATH=~/opencv_contrib-3.4.0/modules \

in the CMake file after having downloaded the repository

Any advice ?

UPDATE: I tried to install your full package…still the same issue…

Hi vincent.dufour,

Can you show this result?

import cv2
import sys
print(cv2.getBuildInformation())
print(sys.version)

If “To be built” has “tracking”, you can use tracking api.

To be built:                 aruco bgsegm bioinspired calib3d ccalib core cudaarithm cudabgsegm cudacodec cudafeatures2d cudafilters cudaimgproc cudalegacy cudaobjdetect cudaoptflow cudastereo cudawarping cudev cvv datasets dnn dnn_objdetect dpm face features2d flann freetype fuzzy hdf hfs highgui img_hash imgcodecs imgproc java_bindings_generator line_descriptor ml objdetect optflow phase_unwrapping photo plot python2 python_bindings_generator reg rgbd saliency shape stereo stitching structured_light superres surface_matching text tracking ts video videoio videostab xfeatures2d ximgproc xobjdetect xphoto

Hi naisy,

thank you for your support I finally managed to install it correctly and make it work and yes ‘tracking’ is present in the list so it’s all good now.

Thank you

Hi Naisy

Got the same error:

module ‘cv2’ has no attribute ‘TrackerKCF_create’

When I run the print(cv2.GetBuildInformation) I dont see Tracker!

So the solution is to build opencv 3.2 with command:

-D OPENCV_EXTRA_MODULES_PATH=~/opencv_contrib-3.4.0/modules \

Thanks,

sojohans

Hi vincent.dufour,
I tried install opencv-contrib with flag “-D OPENCV_EXTRA_MODULES_PATH=~/opencv_contrib-3.4.0/modules”, but still NO “tracking” in “To be built”.
Can you tell me how did you do to solve this?

“Module opencv_tracking disabled because opencv_dnn dependency can’t be resolved!”

so, you need BUILD_opencv_dnn=ON (the goturn tracker depends on dnn)

add “-D BUILD_opencv_dnn=ON” when cmake