Edited 5:13 7/18/2016
Is there something like measure of how much pixels changed in few milliseconds?
I want to be able to tell which is it and depending on it I will choose course of action (for now just print 0 or 1). How would I do that?
Should I be comparing last two images or something else?
You seem to be asking quite a number of questions here, it's probably best if you split them up.
However, to answer the specific issue of how to get the screen info you need to get your algorithm to work... You can use a method like this to work with a video stream from the Windows API.
My advice is to find a way to record a very short stream with a mostly accurate start and end times, then you can use this information to compare each frame in the stream at a timeline you decide on and you can calculate the pixel delta as either an average as cxyzs7 mentioned... aka (in a very notional way)
//do in a loop of some kind of your choice
cv::Mat diff = (f1(roi) != f2(roi));
//followed by a calculation of how long it's been since the last change
if(diff == a_Mat_ofZeros)
changeDetected[i++] = 1;
else changeDetected[i++] = 0;
//then track the changes through an array in a loop
And here is how you do ROI stuff.
Or, you can use this guide histogram calculation in order to find the values as a group and then compare the changes in histogram values in order to detect the changes of specific values, colors, or saturation etc... rather than an ROI.
The important thing is to make sure you have an accurate time for each frame, which is much easier to calculate based on a video stream rather than a string of singular screen caps.
The screen caps out of a stream will give you frames that are more accurate relative to each other, so there will be some lag time between the screen output and the calculations of the differences, but if it's a short enough loop it should be fast enough to give you the results as accurately as you need them.