Match Descriptors Between Two Views
Introduction to Feature Matching
Welcome to Unit 4 of our course. Up to this point, you have learned how to preprocess images and extract visual fingerprints by detecting keypoints and computing their descriptors.
Now, we are ready to tackle the first real dependency in our image stitching pipeline: feature matching. Finding keypoints in an isolated image is a great start, but to stitch a panorama, we must find the exact same points across two different views. By matching these descriptors, we create the critical links needed to eventually align and stitch images.
In this lesson, we will build a reliable feature matcher using OpenCV. We will configure our matcher based on descriptor data type and use Lowe's Ratio Test, a powerful technique for filtering out ambiguous matches.
Handling Different Descriptor Types
Different algorithms produce different descriptor formats. SIFT produces arrays of floating-point numbers. ORB and AKAZE produce compact binary descriptors, represented as 8-bit unsigned integers.
Because our pipeline supports all three methods, our matcher needs to inspect the descriptor type before choosing a matching strategy.
If the descriptor dtype is np.uint8, we treat it as binary. Otherwise, we treat it as a floating-point descriptor such as SIFT.
Lowe's Ratio Test
When matching descriptors, the algorithm computes distances between numeric fingerprints. A shorter distance means two descriptors look more similar.
For each descriptor in the first image, we ask for the two nearest candidates in the second image. The best candidate should be clearly better than the runner-up. If the two candidates are too close in quality, the match is ambiguous and should be rejected.
Now compare that with an ambiguous case:
The ratio acts like a strictness dial:
- Lower values, such as
0.65, are stricter and produce fewer matches. - Higher values, such as
0.85, are looser and may keep more false matches.
The core filtering loop is short:
