image_checker.py 文件源码

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

项目:muDroid 作者: Yuan-W 项目源码 文件源码
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
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号