Image and contour moments
Summarize how a region’s mass is distributed over its coordinates.
The inward notch distinguishes the original boundary from its convex hull.
Accumulate powers of x and y weighted by pixel mass.
Shift to the centroid and normalize scale.
The centroid and axes illustrate geometric descriptors. They summarize the region rather than reproducing every boundary sample.
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
Experiment at pixel level
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.
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
Compute centroids and orientation, or compare shape descriptors under translation, scale and rotation.
How it works
- 01Accumulate powers of x and y weighted by pixel mass.
- 02Shift to the centroid and normalize scale.
- 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.