def checkSimilarPictures(pic1, pic2, x_max=DIFF_THRESHOLD, y_max=DIFF_THRESHOLD):
# print pic1, pic2
image1 = Image.open(pic1).convert('L')
image2 = Image.open(pic2).convert('L')
diff = ImageChops.difference(image1, image2)
box = diff.getbbox()
if box is None:
return True, False
xdiff = abs(box[0] - box[2])
ydiff = abs(box[1] - box[3])
if(xdiff >= x_max and ydiff >= y_max):
# print 'Box', xdiff, ydiff
h = diff.histogram()
sq = (v*(i**2) for i, v in enumerate(h))
sum_of_squares = sum(sq)
rms = math.sqrt(sum_of_squares/float(image1.size[0] * image1.size[1]))
# print rms
if rms > RMS_THRESHOLD:
# print 'RMS', rms
if(xdiff >= CRASH_THRESHOLD and ydiff >= CRASH_THRESHOLD):
return False, True
return False, False
return True, False
评论列表
文章目录