FLANN nearest neighbours
Organize descriptors so nearest-neighbour queries can avoid an exhaustive scan.
A short binary descriptor makes pairwise differences visible. Orange is the query; violet rows are candidates.
This binary example counts unequal bits. Float descriptors instead need an appropriate numeric distance.
The best candidate has the smallest descriptor distance. Index search can avoid inspecting every candidate for larger collections.
The best match is evidence of similar appearance. Ambiguity filtering and geometric verification remain separate steps.
Return nearest candidates and their distances.
Illustrative example. The stages explain the method; they are not a live OpenCV execution.
Try it on an image
Experiment at pixel level
Compute float SIFT descriptors and match them with FLANN. A ratio test removes ambiguous nearest neighbours.
The engine loads on your first run. Your images stay in this browser.
Scroll over either image to zoom at the pointer. Use the scrollbars to pan both views over the same relative area. Zoom is relative to the input; pixel coordinates belong to each image. Warps can change scene correspondence.
Pixel inspector RGBA · native values · matched scale · 9 × 9 output pixels
Select a pixel
Select a pixel
When to use it
Search larger descriptor collections where approximate neighbours are an acceptable speed tradeoff.
How it works
- 01Build an index suited to the descriptor representation.
- 02Visit promising parts of the index for each query.
- 03Return nearest candidates and their distances.
index build cost + reduced work per query
What to tune
Tree or hash settings govern indexing; search checks trade query cost against recall. Keep the training data valid as required by the index API.
Where it breaks down
Index type, distance and descriptor dtype must agree. Approximation can miss the exact nearest neighbour.
TypeScript API
Open an entry for its exact overloads, parameter descriptions, result ownership and pinned upstream source.
All of these calls execute on the CPU. Native objects need explicit disposal. See matrices and ownership and build compatibility.
Related methods
Template matching
Slide a patch across an image and score how well it agrees at each location.
Phase correlation
Estimate translation from the phase relationship between two images in the frequency domain.
ECC alignment
Refine a warp by maximizing enhanced correlation between an image and a template.
Brute-force descriptor matching
Compare each query descriptor with every training descriptor using a chosen distance.