How to do it...

Most often, patches are defined as squares of odd sizes centered at the keypoint position. The similarity between two square patches can then be measured by comparing the corresponding pixel intensity values inside the patches. A simple Sum of Squared Differences (SSD) is a popular solution. The feature matching strategy then works as follows. First, the keypoints are detected in each image. Here, let's use the FAST detector:

  1. Define two keypoints vectors to store the points detected in for each image, as shown in the following code:
// Define keypoints vector 
std::vector<cv::KeyPoint> keypoints1; 
std::vector<cv::KeyPoint> keypoints2;  
  1. Create the FAST detector with a thresold of 80:
cv::Ptr<cv::FeatureDetector> ptrDetector; ...

Get OpenCV 4 Computer Vision Application Programming Cookbook - Fourth Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.