Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Check if Mat is a black image

Tags:

image

opencv

mat

Maybe an easy question but since I am a noob I dont know how to do it in an elegant way. I am analyzing video. For that I am taking differences between the frames. If nothing has changed the resulting frame will be empty or black if I display it with imshow(...). How do I find out if I am looking of one of these black (empty) frames?

I tried:

Mat threshold_output;
...
threshold_output.empty() --> does not work
or
threshold_output == 0 --> compiler error

Maybe someone can tell me :).

Thx

like image 912
user2175762 Avatar asked Jan 11 '23 14:01

user2175762


2 Answers

you can use minMaxLoc and check whether maxVal == 0 :

// Localizing the best match with minMaxLoc
double minVal; double maxVal; 

minMaxLoc( threshold_output, &minVal, &maxVal);
like image 153
Rosa Gronchi Avatar answered Jan 22 '23 02:01

Rosa Gronchi


I solved the problem with this:

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

Thanks!

like image 37
user2175762 Avatar answered Jan 22 '23 04:01

user2175762