输入图像,输出图像内非0元素个数
源码位置:core/src/count_non_zero.dispatch.cpp
int countNonZero(InputArray _src)
{
CV_INSTRUMENT_REGION();
int type = _src.type(), cn = CV_MAT_CN(type);
CV_Assert( cn == 1 );
#if defined HAVE_OPENCL || defined HAVE_IPP
int res = -1;
#endif
#ifdef HAVE_OPENCL
CV_OCL_RUN_(OCL_PERFORMANCE_CHECK(_src.isUMat()) && _src.dims() <= 2,
ocl_countNonZero(_src, res),
res)
#endif
Mat src = _src.getMat();
CV_IPP_RUN_FAST(ipp_countNonZero(src, res), res);
CountNonZeroFunc func = getCountNonZeroTab(src.depth());
CV_Assert( func != 0 );
const Mat* arrays[] = {&src, 0};
uchar* ptrs[1] = {};
NAryMatIterator it(arrays, ptrs);
int total = (int)it.size, nz = 0;
for( size_t i = 0; i < it.nplanes; i++, ++it )
nz += func( ptrs[0], total );
return nz;
}