I'm trying to create a program that checks if 2 images are the same. I have the following code which gets executed with both the images:
img = cv2.imread('canvas.png')
mask = np.zeros(img.shape[:2],np.uint8)
bgdModel = np.zeros((1,65),np.float64)
fgdModel = np.zeros((1,65),np.float64)
rect = (70,70,300,250)
cv2.grabCut(img,mask,rect,bgdModel,fgdModel,5,cv2.GC_INIT_WITH_RECT)
mask2 = np.where((mask==2)|(mask==0),0,1).astype('uint8')
img = img*mask2[:,:,np.newaxis]
img = img[84:191, 84:203]
count = 1
cv2.imwrite("tmp/"+str(count)+".png", img)
First time I run this, I get the following output: First image. After some time ~7 seconds, I do it with exactly the same image, and I get the following output: Second image. I tried it again, and I again got a different output: Third try?
I'm trying to check if the image is the same (as in the contents), but I can't get this working. I'm using the following piece of code found on Stackoverflow to check similarities:
def is_similar(image1, image2):
return image1.shape == image2.shape and not(np.bitwise_xor(image1,image2).any())
And that returns false when check the first with the second image. How can I make this work out?
Thanks for your time,
==== EDIT ====
Here is canvas.png
==== EDIT 2 ====
After looking at @Rotem their answer, I've tried it out, but it still shows a slight difference, which the function above return False on:
and 
'canvas.png', to make the problem reproducible?