Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I have a matrix that is dynamically being changed according to the following code;

 for( It=all_frames.begin(); It != all_frames.end(); ++It)
{
    ItTemp = *It;

    subtract(ItTemp, Base, NewData);

    cout << "The size of the new data for ";
    cout << " is \n" << NewData.rows << "x" << NewData.cols << endl;
    cout << "The New Data is: \n" << NewData << endl << endl;

    NewData_Vector.push_back(NewData.clone());

}

What I want to do is determine the frames at which the cv::Mat NewData is a zero matrix. I've tried comparing it to a zero matrix that is of the same size, using both the cv::compare() function and simple operators (i.e NewData == NoData), but I can't even compile the program.

Is there a simple way of determining when a cv::Mat is populated by zeroes?

like image 407
JM92 Avatar asked Dec 17 '12 02:12

JM92


People also ask

What is use of mat class in OpenCV?

The Mat class of OpenCV library is used to store the values of an image. It represents an n-dimensional array and is used to store image data of grayscale or color images, voxel volumes, vector fields, point clouds, tensors, histograms, etc.

What is a CV :: mat?

In OpenCV the main matrix class is called Mat and is contained in the OpenCV-namespace cv. This matrix is not templated but nevertheless can contain different data types. These are indicated by a certain type-number. Additionally, OpenCV provides a templated class called Mat_, which is derived from Mat.

How do I know if my CV mat is empty?

The Mat object has an empty property, so you can just ask Mat to tell you if it has something or it's empty. The result will be either true or false .


1 Answers

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.

like image 114
JM92 Avatar answered Oct 15 '22 02:10

JM92