检查两个图像是否相等

2024-09-28 23:42:26 发布

您现在位置:Python中文网/ 问答频道 /正文

def images_the_same(image1, image2):
    """
    :param image1: path of image1
    :param image2: path of image2
    :return: True if images are the same, False if images are not the same
    """
    im1 = cv.imread(image1)
    im2 = cv.imread(image2)

    if im1.shape != im2.shape:
        return False

    difference = cv.subtract(im1, im2)
    b, g, r = cv.split(difference)

    if cv.countNonZero(b) == 0 and cv.countNonZero(g) == 0 and cv.countNonZero(r) == 0:
        return True
    return False
print(images_the_same('cards/firstone.png', 'current_card.png'))  # result = True
print(images_the_same('current_card.png', 'cards/firstone.png'))  # result = False

第一个函数调用的结果如何可能不同,而第二个不同顺序的函数调用显示不同的结果?几天前还不错。这里少了什么东西吗?功能是否未正确实现


Tags: thefalsetruereturnifparampngcv