Homography and RANSAC
Estimate a projective mapping between two views of a plane, rejecting inconsistent point matches.
Eight tentative matches include two inconsistent pairs, shown in orange.
A transform proposed from an unsuitable sample does not align the plane. RANSAC tries additional small samples.
Project each reference point and compare it with its observed partner. Orange arrows expose the two large residuals; mint rings mark agreeing pairs.
The accepted mapping bends a rectangular grid into perspective. Every grid intersection uses the same projective transform as the inlier points.
Refine the mapping using the accepted correspondences.
Illustrative example. The stages explain the method; they are not a live OpenCV execution.
Try it on an image
Experiment at pixel level
Map the four image corners to a trapezoid and warp the image. This experiment isolates projective warping; correspondence fitting is a separate step.
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
Locate a poster, rectify a document, or align a planar surface seen from a new viewpoint.
How it works
- 01Propose a homography from a small sample of correspondences.
- 02Measure reprojection errors and mark the agreeing matches as inliers.
- 03Refine the mapping using the accepted correspondences.
s[x′,y′,1]ᵀ = H[x,y,1]ᵀ
What to tune
Choose a robust estimation method and reprojection threshold in pixel units. Inspect the inlier mask, spatial coverage and reprojection error.
Where it breaks down
Parallax from a 3D scene cannot generally be explained by one homography. Collinear points and repeated texture make estimation unstable.
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
Image resizing
Sample the source on a new pixel grid at a different resolution.
Arbitrary remapping
Provide a source coordinate for every destination pixel.
Affine transformations
Map points with a linear transform plus translation, preserving straight lines and parallelism.
Polar and log-polar warps
Re-express an image using angle and radius around a chosen centre.