You need to complete the following steps:
- Import the necessary modules:
import cv2import numpy as npimport matplotlib.pyplot as plt
- Load the two train images:
img0 = cv2.imread('../data/people.jpg', cv2.IMREAD_GRAYSCALE)img1 = cv2.imread('../data/face.jpeg', cv2.IMREAD_GRAYSCALE)
- Detect the keypoints and computer descriptors for each training image:
detector = cv2.ORB_create(500)_, fea0 = detector.detectAndCompute(img0, None)_, fea1 = detector.detectAndCompute(img1, None)descr_type = fea0.dtype
- Construct the BoW vocabulary:
bow_trainer = cv2.BOWKMeansTrainer(50)bow_trainer.add(np.float32(fea0))bow_trainer.add(np.float32(fea1))vocab = bow_trainer.cluster().astype(descr_type))
- Create an object for computing global image ...