Ok, let's assume than your images are different at the moment they change (random). How do we detect that it's another image, different from the previous one?
We are going to extract 3 features of your image and it is: the mean of the RED CHANNEL, GREEN CHANNEL and BLUE CHANNEL (it's a vector). So, if the image is the same, the 3 means are the same, but if it's different, the image has been changed.
So think we are in a infinite loop (your while
).
while(true) {
// we are going to say here if the image has changed or not
}
Are we ok ? So this is the code:
image = cvLoadImage("ayman.jpg", 1);
Scalar meanOfImage = mean(image);
while (true) {
Scalar meanAtThisMoment = mean(image);
// This are the three features (it's in real one, but one vector of 3).
// We are going to compare the three to be more clear.
if (meanAtThisMoment[0] == meanOfImage[0]
&&
meanAtThisMoment[1] == meanOfImage[1]
&&
meanAtThisMoment[2] == meanOfImage[2]) {
cout << endl << "The image hasn't been changed yet.";
image = cvLoadImage("ayman.jpg", 1); // added!! forgot this, sorry
} else {
cout << endl << "The image has been changed!!!";
// and now we set the meanOfImage (the main mean) of the new image to compare with the future images.
meanOfImage = meanAtThisMoment;
}
}