Difference gives an image and you need a simple number so you need to find out if all the pixels in the difference image are zero value, which means every pixel is identical.

See PIL.ImageStat.Stat

Get the mean from the stats and compare it to some small value to test if the images are the same.

Note that a pixel difference can't tell if two images look similar. It just calculates the difference between each pixel. A tiny offset in position between the two images, or one being slightly brighter or darker than the other will result in the images being rated as different.

Well spotted. getbbox returnes the minimum rectangle that contains all non-zero pixels in the image and if all pixels are zero, because the two images are exactly the same in every pixel, he bounding rectangle will be null.

thanks
I tried the code :
Flag = 1 if ImageChops.difference(im2, im1).getbbox() == None else 0
but got the following message on the console.

I'm also worried that the change of light at sunset
will result in the images being rated as different

about
PIL.ImageStat.Stat
I didn't find much information

Maybe I'm thinking wrongly about the solution. What I need to do is to take photos
with the raspberry pi 3 and compare the photo with the previous one and if they are
not the same send them to google cloud vision and then...

as it is not a critical process and where this rpi3 does not have a good internet
connection so I need to compare the images every so often.

if anyone has any idea since all the code regarding google cloud vision is ready

Maybe I'm thinking wrongly about the solution. What I need to do is to take photos
with the raspberry pi 3 and compare the photo with the previous one and if they are
not the same send them to google cloud vision and then...

No two separately taken images will ever be the same in the ImageChops.difference sense. There will always be some pixels that differ.
So you probably need a way to detect significant differences in the presence of insignificant differences..

A good startingpoint might be the package "Motion" that should bein the repositories.
That compares successive images for significant changes and can save still images or video when changes are detected.

There are much smarter ways to do this sort of thing but itdoes getcomplex. Beyondlooking for pixels changing brightnss you could look for connected areas of pixels moving together, having the rough size and shape of a huma. You couldlook atpatterns of motion. You could use tensor flow AI to identify what's in the scene from shapes and motions. But that is all heavy stuff.

OpenCV is a great resource for this sort of thing but look for examples that do what you want. Computer vision is a really big subject.
You will find examples using OpenCV to detect faces in an image. Maybe that would help.

I suggest you start with Motion and see how well that detect changes that interest you. If that works for you write a script that posts the images saved by Motion off to the cloud for whatever processing you want to do there

the images I need to detect on screen sometimes change every 3 minutes at other times change every 15 minutes,
that is not a video are images.

Do you want a 'spot the difference' function?
Can the lighting change? Almost certainly it can.
It is possible to make a system detect that an object that has been present for some time has gone or that a new object has appeared, but that is significantly more complex than just subtracting pixels. That is the basic operation, but you will need appropriate time-based filtering, compensation for lighting changes and noise filters to avoid lots of false alarms and missed events.
Are you looking for periodic changes (happen every 3 minutes on the dot)?
If you describe what you are trying to do you might get more useful answers.

I stupidly just looked at the code on the last post and assumed it was for checking image files that had got renamed or such like, and eliminating duplicates. On reading more of the thread I see that it is to check images from the pi camera, for which this code is completely useless as every single image will be different!

However you can do something pretty effective by setting a threshold then counting how many pixels were outside that. Along the lines of