How to compare 2 images to check if it is identical. The easiest way is to compare pixel by pixel of the 2 images.
In my example, I am using Python Pillow to compare. To install it in macOS, just run these 2 lines
python3 -m pip install --upgrade pip
python3 -m pip install --upgrade Pillow
For other OS, you can refer to their official site at https://pillow.readthedocs.io/en/stable/installation.html
The source code of my function