How to add "Tracker" in openCV python 2.7

Im working with python 2.7 and opencv 3.1 I want to run code to track objects like this:

import cv2
import sys

if __name__ == '__main__' :

    # Set up tracker.
    # Instead of MIL, you can also use
    # BOOSTING, KCF, TLD, MEDIANFLOW or GOTURN

    tracker = cv2.Tracker_create("MIL")

    # Read video
    video = cv2.VideoCapture("videos/chaplin.mp4")

    # Exit if video not opened.
    if not video.isOpened():
        print "Could not open video"
        sys.exit()

    # Read first frame.
    ok, frame = video.read()
    if not ok:
        print 'Cannot read video file'
        sys.exit()

    # Define an initial bounding box
    bbox = (287, 23, 86, 320)

    # Uncomment the line below to select a different bounding box
    # bbox = cv2.selectROI(frame, False)

    # Initialize tracker with first frame and bounding box
    ok = tracker.init(frame, bbox)

but when I run it, I encounter this error:

AttributeError: 'module' object has no attribute 'Tracker_create'

Here is the source code: http://www.learnopencv.com/object-tracking-using-opencv-cpp-python/ Im looking for solutions, but I cannot find anything useful ... what can I do to add this module to my opencv library?

+4
source share
5 answers

Just install opencv-contrib-python

pip install opencv-contrib-python

and it will work!

+7
source

, OpenCV opencv_contrib. . , this blogpost.

EDIT:

Windows, @Osama

, .

+1

, - .whl . @foobar @kyjanond, .whl .

OpenCV: https://pypi.python.org/pypi/opencv-python/3.3.0.10

OpenCV https://pypi.python.org/pypi/opencv-contrib-python/3.3.0.10

OpenCV 3.3.0 Python 2.7, :

  • opencv_python-3.3.0.10-cp27-cp27m-win32.whl
  • opencv_contrib_python-3.3.0.10-cp27-cp27m-win32.whl

, :

  • python -m pip install opencv_python-3.3.0.10-cp27-cp27m-win32.whl
  • python -m pip install opencv_contrib_python-3.3.0.10-cp27-cp27m-win32.whl

, OpenCV .

GitHub:


tracker_types = ['BOOSTING', 'MIL','KCF', 'TLD', 'MEDIANFLOW', 'GOTURN']

tracker_type = tracker_types[1]

tracker = cv2.Tracker_create(tracker_type)


tracker_types = ['BOOSTING', 'MIL','KCF', 'TLD', 'MEDIANFLOW', 'GOTURN']

tracker_type = tracker_types[1]

if tracker_type == tracker_types[0]:
    tracker = cv2.TrackerBoosting_create()
elif tracker_type == tracker_types[1]:
    tracker = cv2.TrackerMIL_create()
elif tracker_type == tracker_types[2]:
    tracker = cv2.TrackerKCF_create()
elif tracker_type == tracker_types[3]:
    tracker = cv2.TrackerTLD_create()
elif tracker_type == tracker_types[4]:
    tracker = cv2.TrackerMedianFlow_create()
elif tracker_type == tracker_types[5]:
    tracker = cv2.TrackerGOTURN_create()

, , .

+1

openCV , : TrackerKCF_create() .

0

. /usr/local/.
, Python OpenCV.

.

  • Python Path: Python , import sys;print sys.path Python. . /usr/local/lib/python2.7/site-packages/cv2.so . , su mv /usr/local/lib/python2.7/site-packages/cv2.so /usr/lib/python2.7/ → site-packages. OpenCV.

  • /usr/local/lib/python2.7/site-packages PYTHON_PATH: . ~/.bashrc , . export PYTHONPATH=$PYTHONPATH:/usr/local/lib/python2.7/site-packages. , OpenCV . import cv2.

0

Source: https://habr.com/ru/post/1670510/


All Articles