When you simply pass the default values (alpha = 1.0 or beta = 0.0), you need not have
performance fears; OpenCV is smart enough to recognize these cases and not waste processor time on
useless operations.
A similar result can be achieved, with somewhat greater generality using matrix algebra:
Mat_<uchar> B = saturate_cast<uchar>(
cv::abs( src * alpha + beta )
)
This method will also generalize to types other than uchar:
Mat_<unsigned short> B = saturate_cast<unsigned short>(
cv::abs( src * alpha + beta )
)
cv::countNonZero()
int cv::countNonZero( // Return number of non-zero elements in mtx
cv::InputArray mtx, // Input array
);
cv::countNonZero() returns the number of nonzero pixels in the array mtx.
cv::cvarrToMat()
cv::Mat cv::cvarrToMat(
const CvArr* src, // Input array: CvMat, IplImage, or CvMatND
bool copyData = false, // if false just make new header, else copy data
bool allowND = true, // if true, and possible, convert CvMatND to Mat
int coiMode = 0 // if 0: error if COI set, if 1: ignore COI
);
cv::cvarrToMat() is used when you have an “old-style” (pre-version 2.1) image or matrix type and
you want to convert it to a “new-style” (version 2.1 or later, which uses C++) cv::Mat object. By default,
only the header for the new array is constructed without copying the data. Instead, the data pointers in the
new header ...