6. Object Tracking
Activity 6.01: Implementing Autofocus Using Object Tracking
Solution:
- Create a new Jupyter Notebook called
Activity6.01.ipynb
. We will be writing our code in this. - First, import the modules we will need:
# Import modules import cv2 import numpy as np import dlib
- 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!")
- 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...