Skip to Content
OpenCV 3 Computer Vision with Python Cookbook
book

OpenCV 3 Computer Vision with Python Cookbook

by Aleksei Spizhevoi, Aleksandr Rybnikov
March 2018
Beginner to intermediate
306 pages
9h 54m
English
Packt Publishing
Content preview from OpenCV 3 Computer Vision with Python Cookbook

How to do it...

The steps for this recipe are:

  1. Import all of the necessary modules:
import cv2import numpy as np
  1. Open a video file, read its frame, and select an object to track:
cap = cv2.VideoCapture("../data/traffic.mp4")_, frame = cap.read()bbox = cv2.selectROI(frame, False, True)cv2.destroyAllWindows()
  1. Create the Median Flow tracker and initialize it with the first frame from the video and the bounding box we've selected. Then, read the remaining frames one-by-one, feed them into the tracker, and get a new bounding box for each frame. Display the bounding box, as well as the number of frames that the Median Flow algorithm is able to process each second:
tracker = cv2.TrackerMedianFlow_create()status_tracker = tracker.init(frame, ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Learning OpenCV 3 Computer Vision with Python (Update)

Learning OpenCV 3 Computer Vision with Python (Update)

Joe Minichino, Joseph Howse
OpenCV 4 with Python Blueprints - Second Edition

OpenCV 4 with Python Blueprints - Second Edition

Dr. Menua Gevorgyan, Michael Beyeler (USD), Arsen Mamikonyan, Michael Beyeler

Publisher Resources

ISBN: 9781788474443Supplemental Content