Skip to content

countNonZero

Core and matricesfunctionOpenCV 5.0.0
import { countNonZero } from '@banou/opencv-wasm'

Use after await initOpenCV(). See the initialization and named imports guide.

ARGUMENTSsrc
FUNCTIONcountNonZero
RETURN TYPEnumber
Call structure. A void return can still write to destination arguments. The parameter descriptions define inputs, outputs and ownership.

Counts non-zero array elements.

The function returns the number of non-zero elements in src :

\sum _{I: \; \texttt{src} (I) \ne0 } 1

The function do not work with multi-channel arrays. If you need to count non-zero array elements across all the channels, use Mat::reshape first to reinterpret the array as single-channel. Or you may extract the particular channel using either extractImageCOI, or mixChannels, or split.

Note: - CV_16F/CV_16BF/CV_Bool/CV_64U/CV_64S/CV_32U are not supported for src.

  • If only whether there are non-zero elements is important, hasNonZero is helpful.
  • If the location of non-zero array elements is important, findNonZero is helpful.

See: mean, meanStdDev, norm, minMaxLoc, calcCovarMatrix See: findNonZero, hasNonZero

countNonZero(src: Mat): number;
src

single-channel array.

Returns

The number result.

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.