Affine transformations
Map points with a linear transform plus translation, preserving straight lines and parallelism.
This example applies a known rotation, scale and translation to the source.
The transformation combines a rotation and scale about the image centre with a final translation.
Orange arrows run from destination positions back to their source locations. Inverse mapping avoids leaving gaps between output samples.
The output preserves straight lines under this affine transform. Locations outside the source need an explicit border rule.
Resample the source and fill uncovered borders.
Illustrative example. The stages explain the method; they are not a live OpenCV execution.
Try it on an image
Experiment at pixel level
Rotate and scale around the image centre with a constant black border.
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
Align images under rotation, scale, shear and translation, or rotate around a chosen centre.
How it works
- 01Estimate or construct a 2×3 transformation matrix.
- 02Map the output grid back to the input grid.
- 03Resample the source and fill uncovered borders.
[x′,y′]ᵀ = A[x,y]ᵀ + t
What to tune
WARP_INVERSE_MAP declares the direction of a supplied warp; dsize chooses the output canvas.
Where it breaks down
Affine models cannot describe general perspective distortion. Robust estimation needs enough well-distributed correspondences.
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.
Homography and RANSAC
Estimate a projective mapping between two views of a plane, rejecting inconsistent point matches.
Polar and log-polar warps
Re-express an image using angle and radius around a chosen centre.