Search icon CANCEL
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
The Computer Vision Workshop

You're reading from   The Computer Vision Workshop Develop the skills you need to use computer vision algorithms in your own artificial intelligence projects

Arrow left icon
Product type Paperback
Published in Jul 2020
Publisher Packt
ISBN-13 9781800201774
Length 568 pages
Edition 1st Edition
Languages
Tools
Arrow right icon
Authors (3):
Arrow left icon
Nikhil Singh Nikhil Singh
Author Profile Icon Nikhil Singh
Nikhil Singh
Hafsa Asad Hafsa Asad
Author Profile Icon Hafsa Asad
Hafsa Asad
Vishwesh Ravi Shrimali Vishwesh Ravi Shrimali
Author Profile Icon Vishwesh Ravi Shrimali
Vishwesh Ravi Shrimali
Arrow right icon
View More author details
Toc

6. Object Tracking

Activity 6.01: Implementing Autofocus Using Object Tracking

Solution:

  1. Create a new Jupyter Notebook called Activity6.01.ipynb. We will be writing our code in this.
  2. First, import the modules we will need:
    # Import modules
    import cv2
    import numpy as np
    import dlib
  3. Next, create a VideoCapture object and check whether it opened successfully or not:

    Note

    The video can be downloaded from https://packt.live/2NHXwpp. Before proceeding, ensure that you can change the path to the video (highlighted) based on where the video is saved in your system.

    # Create a VideoCapture Object
    video = cv2.VideoCapture("../data/soccer2.mp4")
    # Check if video opened successfully
    if video.isOpened() == False:
        print("Could not open video!")
  4. Next, capture the first frame of the video and check whether we are able to read the frame successfully or not:
    # Read first frame
    ret, frame = video.read()
    # Check if frame read successfully
    if...
lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at R$50/month. Cancel anytime