Moments
import type { Moments } from '@banou/opencv-wasm'core_basic raster image moments //////////////////////////
struct returned by cv::moments
The spatial moments \texttt{Moments::m}_{ji} are computed as:
\texttt{m} _{ji}= \sum _{x,y} \left ( \texttt{array} (x,y) \cdot x^j \cdot y^i \right )
The central moments \texttt{Moments::mu}_{ji} are computed as:
\texttt{mu} _{ji}= \sum _{x,y} \left ( \texttt{array} (x,y) \cdot (x - \bar{x} )^j \cdot (y - \bar{y} )^i \right )
where (\bar{x}, \bar{y}) is the mass center:
\bar{x} = \frac{\texttt{m}_{10}}{\texttt{m}_{00}} , \; \bar{y} = \frac{\texttt{m}_{01}}{\texttt{m}_{00}}
The normalized central moments \texttt{Moments::nu}_{ij} are computed as:
\texttt{nu} _{ji}= \frac{\texttt{mu}_{ji}}{\texttt{m}_{00}^{(i+j)/2+1}} .
Note: \texttt{mu}_{00}=\texttt{m}_{00}, \texttt{nu}_{00}=1
\texttt{nu}_{10}=\texttt{mu}_{10}=\texttt{mu}_{01}=\texttt{mu}_{10}=0 , hence the values are not
stored.
The moments of a contour are defined in the same way but computed using the Green's formula (see http://en.wikipedia.org/wiki/Green_theorem). So, due to a limited raster resolution, the moments computed for a contour are slightly different from the moments computed for the same rasterized contour.
Note: Since the contour moments are computed using Green formula, you may get seemingly odd results for contours with self-intersections, e.g. a zero area (m00) for butterfly-shaped contours.
export type Moments = {
m00: number,
m10: number,
m01: number,
m20: number,
m11: number,
m02: number,
m30: number,
m21: number,
m12: number,
m03: number,
mu20: number,
mu11: number,
mu02: number,
mu30: number,
mu21: number,
mu12: number,
mu03: number,
nu20: number,
nu11: number,
nu02: number,
nu30: number,
nu21: number,
nu12: number,
nu03: number
};These signatures describe this package. Upstream documentation can mention optional backends that are absent from this build. Check runtime compatibility before choosing a backend or file format.