You need to complete the following steps:
- Import the necessary modules:
import cv2import numpy as np
- Define a function which handles a video file. This function takes each frame, match the keypoints for this frame and the one 40 frames before:
def video_keypoints(matcher, cap=cv2.VideoCapture("../data/traffic.mp4"), detector=cv2.ORB_create(40)): cap.set(cv2.CAP_PROP_POS_FRAMES, 0) while True: status_cap, frame = cap.read() frame = cv2.resize(frame, (0, 0), fx=0.5, fy=0.5) if not status_cap: break if (cap.get(cv2.CAP_PROP_POS_FRAMES) - 1) % 40 == 0: key_frame = np.copy(frame) key_points_1, descriptors_1 = detector.detectAndCompute(frame, None) else: key_points_2, descriptors_2 = detector.detectAndCompute(frame, None)