Skip to content

Affine transformations

Map points with a linear transform plus translation, preserving straight lines and parallelism.

Try it on your image ↓

VISUAL WALKTHROUGHGeometry
REFERENCE INPUTSource coordinate frame

This example applies a known rotation, scale and translation to the source.

RESULTResampled output

The output preserves straight lines under this affine transform. Locations outside the source need an explicit border rule.

STEP 03 / 03

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

YOUR IMAGE · REAL OPENCV

Experiment at pixel level

Open full lab ↗

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.

Input448 × 320
OutputWaiting for a result

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
Hover to inspect. Click to pin a pixel.
Input
Select a pixel

Output
Select a pixel

Sample models and licenses

When to use it

Align images under rotation, scale, shear and translation, or rotate around a chosen centre.

How it works

  1. 01Estimate or construct a 2×3 transformation matrix.
  2. 02Map the output grid back to the input grid.
  3. 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.