How to determine if a cv::Mat is a zero matrix?

I used

if (countNonZero(NewData) < 1) 
{
    cout << "Eye contact occurs in this frame" << endl;
}

This is a pretty simple (if perhaps not the most elegant) way of doing it.


To check the mat if is empty, use empty(), if NewData is a cv::Mat, NewData.empty() returns true if there's no element in NewData.

To check if it's all zero, simply, NewData == Mat::zeros(NewData.size(), NewData.type()).

Update:

After checking the OpenCV source code, you can actually do NewData == 0 to check all element is equal to 0.


countNonZero(Mat ) will give u number of non zeros in mat