similar_image.py 文件源码

python
阅读 19 收藏 0 点赞 0 评论 0

项目:hacker-scripts 作者: restran 项目源码 文件源码
def classify_ahash(cls, image1, image2, size=(8, 8), exact=25):
        """ 'image1' and 'image2' is a Image Object.
        You can build it by 'Image.open(path)'.
        'Size' is parameter what the image will resize to it and then image will be compared by the algorithm.
        It's 8 * 8 when it default.
        'exact' is parameter for limiting the Hamming code between 'image1' and 'image2',it's 25 when it default.
        The result become strict when the exact become less.
        This function return the true when the 'image1'  and 'image2' are similar.
        """
        image1 = image1.resize(size).convert('L').filter(ImageFilter.BLUR)
        image1 = ImageOps.equalize(image1)
        code1 = cls.get_code(image1, size)
        image2 = image2.resize(size).convert('L').filter(ImageFilter.BLUR)
        image2 = ImageOps.equalize(image2)
        code2 = cls.get_code(image2, size)

        assert len(code1) == len(code2), "error"

        return cls.compare_code(code1, code2)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号