If you want the total number of pixels, use cv::Mat::total() .
int nPixels = m.total();
Please note that for multi-channel images, the number of pixels is different from the number of elements in the array. Each pixel is most often between one (i.e. shade of gray) and four (i.e. BGRA) elements per pixel.
source share