Skip to content

Image and contour moments

Summarize how a region’s mass is distributed over its coordinates.

Try it on your image ↓

VISUAL WALKTHROUGHShape
REFERENCE INPUTShape with a concavity

The inward notch distinguishes the original boundary from its convex hull.

RESULTCentroid and principal spread

The centroid and axes illustrate geometric descriptors. They summarize the region rather than reproducing every boundary sample.

STEP 03 / 03

Combine normalized moments into descriptors such as Hu invariants.

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 ↗

Mark contour centroids and report area and Hu moments for the largest region.

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

Compute centroids and orientation, or compare shape descriptors under translation, scale and rotation.

How it works

  1. 01Accumulate powers of x and y weighted by pixel mass.
  2. 02Shift to the centroid and normalize scale.
  3. 03Combine normalized moments into descriptors such as Hu invariants.

centroid = (m10 / m00, m01 / m00)

What to tune

binaryImage treats nonzero pixels as equal mass; matchShapes chooses a distance between Hu-based descriptors.

Where it breaks down

Small contour changes and numerical range affect high-order moments. A zero-area region has no defined centroid.

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.